Solved

Button added to UserControl Form not visible

Posted on 2013-12-29
6
510 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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
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…
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…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

910 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

24 Experts available now in Live!

Get 1:1 Help Now