Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Button added to UserControl Form not visible

Posted on 2013-12-29
6
Medium Priority
?
555 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Certified OpenStack Administrator Course

We just refreshed our COA course based on the Newton exam.  With 14 labs, this course goes over the different OpenStack services that are part of the certification: Dashboard, Identity Service, Image Service, Networking, Compute, Object Storage, Block Storage, and Orchestration.

 
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

After several hours of googling I could not gather any information on this topic. There are several ways of controlling the USB port connected to any storage device. The best example of that is by changing the registry value of "HKEY_LOCAL_MACHINE\S…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
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…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

705 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