C# .NET - Show hide buttons problem - Asked By mostafa hamdy on 03-Nov-10 09:44 AM

Hello all
I have some win form in the C# which have 3 buttons exist in some panel control , and I want to show and hide one button  from them at some condition i set , but after I hide some button from them I get space between the button 1 and button 3 , I want to eliminate this space because it's causes conflict and invalide shape , I attached the image of this problem ,

main shape

and after hide the button 2 I get the following shape

but I wish to get some thing like that

 please if any body get what I mean and can help me please send me or tell me about some url may help me in doing that
undhad ashwin replied to mostafa hamdy on 03-Nov-10 10:21 AM
can u set button property inside button


if any query then reply
mostafa hamdy replied to undhad ashwin on 03-Nov-10 10:29 AM
Hi undhad ashwin
really many thanx about ur reply , but it's not clear to me to set the button style to "Display:dynamic"
beacuse there's no property for the button called style and also it's a desktop application not web one, I'm sorry may be some unclear thing to me may u clearify it to be please
Rolf Jaeger replied to mostafa hamdy on 03-Nov-10 10:33 AM
Hi Mostafa:

I wished there was a more elegant solution, but the best I have come up with is listed below (insert this code after the statement that changes the visibility of button2).

Hope this helped,

const int SPACING = 5;
if (!button2.Visible)
  button1.Left = button2.Left + button2.Width / 2 + SPACING/2;
  button3.Left = button2.Left + button2.Width/2 - button3.Width - SPACING/2;
  button1.Left = button2.Left + button2.Width + SPACING;
  button3.Left = button2.Left - button3.Width - SPACING;

Anoop S replied to mostafa hamdy on 03-Nov-10 03:29 PM
You can use Left property of the button according to the condition like
if( button2.visiable==false)
button3.left =xxxx;
button1.left =yyyy;
Kai Fjellstadsveen replied to mostafa hamdy on 10-Nov-10 05:14 PM
Hi. You could put the buttons in an stackpanel like this:
(I've written this by memory so the syntax might be a bit off)
<StackPanel Orientation="Horisontal">
<Button 1 />
<Button 2 />

or in a grid with columnwidth set to auto.
<ColumDefinition Width="Auto" />
<ColumDefinition Width="Auto" />
<ColumDefinition Width="Auto" />
<Button1 />
<Button2 />
So then it's just about setting the buttons visibility to collapsed.

Best wishes