Solved

Button added to UserControl Form not visible

Posted on 2013-12-29
6
504 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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

747 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

18 Experts available now in Live!

Get 1:1 Help Now