At the start of the application, a form must appear with two buttons on it. On the top button, the text “Button 1” must be written and on the bottom button the text “Button 2” must be written. The two buttons must be perfectly center aligned (both horizontally and vertically) in the client area of the form.
For the first time, when any of the button 1 or button 2 is clicked then it will disappear and the other button will stay unchanged. For example, user clicks button 1 for the first time then button 1 will disappear. Button 2 will be unchanged. Now there is only one button on the window that is button 2. On clicking button 2 it will disappear and button 1 will reappear on the window. Now if the user clicks button 1 then it will disappear again and button 2 will reappear. This process may go on indefinitely until the application is terminated by clicking the close button (on the top right corner of the window).
not sure what you are asking for.. but i interpret it as you need a code to make your button visible/not visible
button.visible=true;
button.visible=false;
Look
1- Inside the Event handler of each button just do:
2- change the visible property of the current button to false to hide it.
3- Check if the other button is hidden then make it visible again.
Button1.visible = !Button1.visible;
if (!Button2.visible)
{
Button2.visible= true;
}
PS. that code as a logic and info not i didn't mean a specific programming language.
is it what you search for?
Related
So basically, I have a C# winform and it has multiple pages (which are different forms) when going to one page to another it closes the previous form/page. However, I have a “Settings” page and on that form I have a toggle button. That toggle button changes the text of a label on form1. If I force the form the open while the “settings” form is open, the text changes. However, I do NOT want that form to actually open I just want the text to change but when I take out the form1.Show(); , and just toggle the button off and switch back to form1 the text is the original and when switching back to settings, the toggle button has re-enabled itself. I cannot figure this out.
In my C# Winforms application I have a 'Welcome' window with a number of buttons. One of these is 'Exit' which closes the application. Other buttons replace the window with a task-specific window. All the task Windows have a 'Close' button which returns to the Welcome screen. Conventionally, the Close button is in the same place as the Exit button in the Welcome window.
The problem I have is that some users are trigger happy and double click on the Close buttons. The first click triggers the Close action, and the task window closes. But it would appear that the second click is being bufferred, and is given to the Welcome window once it is displayed, and results in the Exit button being clicked. This is NOT the desired behaviour!
Is there any way I can discard the unwanted second click on the Close button? The task windows raise an AppletClosing event back to the Welcome window when they are closing, so it would be easy to do it in that handler - if I knew what to do.
Thanks for any help - much appreciated.
Kevin
This question already has answers here:
Tray icon does not disappear on killing process
(8 answers)
Closed 9 months ago.
After I send a TB_DELETEBUTTON message to delete a button (of a external application) in the system-tray toolbar, it remains a blank/empty rectangle from that deleted button, and the toolbar does not remove this empty rectangle until I do left or right click on some other icon, then finally the toolbar window gets redrawn and the empty rectangle from he button that I deleted disappears.
This is an aesthetic issue that I would like to avoid. I just would like to programatically update/redraw the toolbar window after I send the TB_DELETEBUTTON message, however after I call the UpdateWindow, UpdateLayeredWindow or RedrawWindow, the empty rectangle of the deleted button remains there.
The flags cobmination that I tried to use with RedrawWindow are: RDW_FRAME, RDW_ALLCHILDREN, RDW_UPDATENOW and RDW_INVALIDATE, all together.
The window handle that I'm passing to these functions is the window with class name: "ToolbarWindow32" (on which reside the system-tray buttons/icons of the applications), a example for getting this window handle can be found here.
My question is: how can I properly update/redraw this window?.
After calling the InvalidateRect function I noticed that the notification area window is redrawn (because the window flicks for a moment), so redrawing the window seems not a valid solution to solve this issue...
However, in the next thread I found a solution:
https://forum.lazarus.freepascal.org/index.php?topic=14847.0
The thing is that in order to "properly" refresh the size of the notification area to remove any empty space from previously deleted buttons, I just need to send WM_LBUTTONDOWN and WM_LBUTTONUP messages through the SendMessage function.
These window messages must be sent two times (at least for Windows 10) to the ToolbarWindow32 window following the next order: WM_LBUTTONDOWN, WM_LBUTTONUP, WM_LBUTTONDOWN, WM_LBUTTONUP. This is to reproduce two single clicks (not a double click) in the first button inside the system-tray, which is what I manually needed to do before applying this automated solution. After sending the messages, the window becomes "auto-sized" properly.
The only aesthetic problem would be if the first button is a button from an application that performs some undesired action when doing a single click on its button, but this is not typical to see. Typically the user only can do a double-click to restore the window from the button on system-tray, or do right click to open its context menu, but nothing should happens for doing a single click on a button... if the developer didn't programmed anything to happen.
Note that this methodology also works when there is the up arrow that contains "hidden" buttons.
I have a main window and a toolstrip on it with different command buttons. In these commands, I've a 'Print' button too (See Below). When I click on 'Print' button , I need to show sub-form as Modal Less Dialog. Because, I've few option on sub-form. If user select them then he/she can interact with Main Form too.
Meanwhile, on show() method I disable all controls on Main Form (see below) as it will be done if I use ShowDialog() method to show sub-form. When I click the Print Button, it's color changed which shows it is focused/selected.
On click sub-form is show like below pic.
Logically, it should return to previous mode when I close sub-form. But, even sub-form is showing... that 'Print' button on Main-Form is still focused/selected. When I close the sub-form, that 'Print' Button still focused/selected like below.
What Event/ Property needs to be changed to make this 'Print' Button to show like as it is in initial state.
I've tried Invalidate(), change BackColor but didn't meet the requirement yet. Any Guidelines ?
Set the CheckOnClick property of your button to false if you don't want it to appear "selected" at all, otherwise toggle the CheckState property on the button when the subform is closed.
Well, Selected Property in ToolStripButton is read only. Anyone, needs to clear the selection of toolstrip buttons can use below method which is invoked via reflections.
MethodInfo method = typeof(ToolStrip).GetMethod("ClearAllSelections", BindingFlags.NonPublic | BindingFlags.Instance);
method.Invoke(yourToolStripName, null);
This comes from : How to Deselect ToolStripItems
Happy Programming.
I have a button, contained in a panel, with a click event, that works fine. However when a users presses another button, I need to move this button into another panel (this is actually a panel with a modalpopupextender), so I this code to do so:
newPanel.Controls.Add(buttonPanel)
It all get's moved and looks fine. However now when the button is clicked it doesn't fire the associated event. I have tried re-adding the event in the page_init, with this code
((Button)this.FindControl("serverModalSave")).Command += new CommandEventHandler(modalSave_Click);
But with no luck. How can I get this button to fire it's click event when moved, and why does it stop working when it's moved?
EDIT:
This Button needs to be added to a panel specified by the user at run time, so there is not a way to determine where the button will go in advance.
I could instead of moving this button, create a new one, but because this button is not created in the page_init I am having issues getting that to fire an event either.
Instead of moving the button, have another button on the other panel set to hidden.
Hide the button you wanted to move and show the hidden one when needed.
Moving the control changes the naming hierarchy and now the button can't be found and the click event can't fire.
This is due to how the page life cycle works. Here is a good (if somewhat dated) article about how view state works - if you understand this, you will understand what went wrong.
If you are creating the button in the new panel, when this button is then clicked do you re-create it in the postback ?
You must re-create all controls on each postback see here