Solved

Button added to UserControl Form not visible

Posted on 2013-12-29
6
519 Views
Last Modified: 2014-01-20
Depending on where I add an 'Apply Changes" button on a UserControl form, it is sometimes not visible.  (BTW: the button forces control to an addhandler to serialize data and control switch setting).  It seems that if the button is added to the lower left or lower right corner of the form, it is visible, but if added to the top, the UserControl seems to mangle the button(?)

Also, there is some interesting behavior if placement of the UserControl is above the added button, and this behavior acts like a button click.  Thus, there seems to be volatility if a button added to a UserControl Form is anywhere near the UserControl.

Below is the code I am using:

 
        Dim myform As New Form
        myuc.autosize = True 'Note myuc is the actual usercontrol, instantiated as an object from usercontrol resources
        myform.AutoSize = True
        myform.Dock = DockStyle.Fill
        myform.Controls.Add(myuc)
        myform.Show()
        myform.Width = 0
        myform.Height = 0
        myform.Width = myuc.width
        myform.Height = myuc.height + 50
        myform.Left = 0
        myform.Top = 0
        Dim btn As New Button
        btn.Text = "Apply"
        btn.Top = myform.Bottom - 50
        btn.Left = myform.Right - 60
        btn.BringToFront()
        myform.Controls.Add(btn)

Open in new window

0
Comment
Question by:lep1
6 Comments
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 39745681
You don't specify a width and height for the button - try setting those values and then it should appear.  (If width and / or height are zero what will you see ?)
0
 
LVL 23

Expert Comment

by:Ioannis Paraskevopoulos
ID: 39745739
I would also advise to check the Anchor property of the button. If it is set to bottom and right, and you put it on the top left corner and resize your user control, you may have the button outside the visible bounds.

Giannis
0
 

Author Comment

by:lep1
ID: 39746156
Thanks for the responses, however, the above recommendations didn't work.  It appears that when the "Apply Changes" button is placed between the user control and the top of the form, the usercontrol tends to act like a button click since the form disappears.  However, if the button is placed at the bottom right or bottom left of the form using the original code (provided above), everything works normally.
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 83

Expert Comment

by:CodeCruiser
ID: 39754938
You do not set the top and left properties of myuc control so it is added as top left location and probably hides the button behind itself or shows it on top.
0
 

Accepted Solution

by:
lep1 earned 0 total points
ID: 39755290
RESOLVED:  I determined the solution myself.  The UserControl must be added to the form after adding the button.   Top, Left, Dockfill, BringtoFront have nothing to do with the issue, and didn't affect the solution.

myform.Controls.Add(btn)
myform.Controls.Add(myuc)

Open in new window

0
 

Author Closing Comment

by:lep1
ID: 39793772
None of the experts solutions worked, however, my solution solved the issue
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now