I created a button in WinForms and generated an event using VS. Somehow the button disappeared. I checked the designer.cs code and found code specifying the button had changed to locates the button somewhere out of the visible form. I changed the designer code to the following:
// startButton
//
this.startButton.Location = new System.Drawing.Point(118, 758);
this.startButton.Margin = new System.Windows.Forms.Padding(6);
this.startButton.Name = "startButton";
this.startButton.Size = new System.Drawing.Size(140, 46);
this.startButton.TabIndex = 17;
this.startButton.Text = "Start";
this.startButton.UseVisualStyleBackColor = true;
this.startButton.Click += new System.EventHandler(this.StartButton_Click);
Prior to my attempt to change the button position back to where it was supposed to be the System.Drawing.Pont was set at -256, 758. I used another button position in the file to determine that the value should have been 118. However, when I restart the program the button is still missing. Why is this happening and how do I get the button back.
If I can't get the button back what happens if I delete the button code in designer.cs and the event handler. Can I then add a new button to replace the old. Just want to make sure that I don't make an irreversible change that compromises the entire program.
Thanks for any suggestions.
The preferred way to set the properties of your controls is through the Design view.
In order to do so you should have the "Properties explorer" visible. The easiest way to make it visible is to click in the "Properties" button on top of the "Solution explorer".
Now, on top of the "Properties explorer" you will find a drop-down list in which you can select all the elements of your form. Just find the button you want to edit, modify its Location property and Save.
Concerning your other question, you can delete your button and recreate it, but its bindings to the event handlers will be lost and you will have to recreate them. You can do this through the "Events" tab of the "Properties explorer".
Related
My Question is how can i Build in Android C# an SreachView this is off by but Show and any User click on this a Dialog open and asked the User to give her ok.
I work in a Fragment
SearchView searchView;
searchView = (SearchView)View.FindViewById(Resource.Id.MenuSearchitem);
searchView.ClearFocus();
searchView.SetOnQueryTextListener(this);
searchView.SetOnQueryTextFocusChangeListener(this);
searchView.SetIconifiedByDefault(false);
searchView.SubmitButtonEnabled = true;
searchView.QueryHint = mapViewModel.AddressPlaceholder;
thats all fine, but nothing work for click on the searchbar and no dialog is open.
follow ways i have used IOnFocusChangeListener and IOnSuggestionListener dont gave the right way for me
you can use onTouchListner, wherever you will touch on the screen the touch event will be triggered, there you can check which widget is clicked just check it and open dialog in it.
I'm using Visual Studio, I have generated a form & added a button but unfortunately I have named btn_test1 instead of Btn_test1 (small vs large beginning letter) & double clicked the button to generate the click function and visual Studio happily generated the: btn_test1_Click() function & then complained that the function didn't start with a capital letter.
I thought: "Ok, no problem", went back & renamed the button to Btn_test1 & changed the click function to Btn_test1_Click() and now instead Visual Studio gives me an error that btn_test1_Click() is missing.
My question is: What is the proper procedure I should have used in this case?
If you don't want to write a long answer but have a link to some documentation it's fine too.
Okay, there is no need for a capital letter at the beginning of a name property, I'm also using VS 2017. I'll give some screenshots how to rename a function.
Step 1: Click on the events of the button in the properties panel as shown in the following image
Step 2: Find click event, and Delete the text
Step 3: Go to Properties in the properties panel
Step 4: Select the Name property of the button.
Step 5: Rename it as you like,
Step 6: Double click the button on the designer, it will automatically create a function with the new name.
As for the naming convention, use as I mentioned in the image.
for example, a button to send something can be named as btnSend.
btn -> stands for button. Send -> represents the name.
Note:
After you have successfully renamed and generated the new click event code. The old click event code will just be there. If you need the content of the old event copy it to the new click event code.
Also, if you still stuck with some error states that the old function is missing. Read the Designer.cs file carefully and delete all lines associated with the old function name.
Form1.cs [Design] crashes when you try to delete the event that is bound with button.
While making such changes -
Go to Button properties and remove the function name from click event.
Change the Button name
Again go to click event and do double click it (VS will generate click event for you)
Now you can delete the previous click event from your code without making your Form1.cs(design) crash.
Alright, so I'm looking for a more or less quick fix for an issue... On a program I've built, The image on a button is changed when a KeyDown event occurs. Initially, I changed the image by saying button1.Image = Image.FromFile(#"......");
The problem is that when I put the program on a USB, the new computer looks for the file on the same pathway and can't find it, creating an error. The only images that load are the ones that are used in the designer area, the ones the buttons start with. So because of that, I made a whole pile of extra buttons, assigned them my needed images, hid them all using Button3.Hide(); . I changed all the button1.Image = Image.FromFile(#"...") to Button1.Image = Button2.Imageand then put it on the stick to try again.
As you may have guessed, it did not work. Any advice on how to make the images work on all computers?
You can bundle the images as part of your executable file by making them an Embedded Resource.
Click on Project --> Properties.
One the Left, Select "Resources".
Now across the Top, click the DropDown Arrow next to "Add Resource"
and Select "Add Existing File".
Navigate to the first Image File and
Double Click it.
In the Properties Pane for the Image (bottom right
by default) change the "Persistence" to "Embedded in.resx".
Repeat steps #3 to #5 for the second Image file.
Now go back to design mode for your Form and select your Button. Click the three dots "..." next to the Image property and you should now see the two Images listed in the bottom half under the "Project resource file:" area. Select the default image from there.
When the KeyDown() event occurs, you can use code like this to change the Image:
button1.Image = Properties.Resources.sv_privilege;
where "sv_privilege" is the name of the resource you embedded earlier and want to switch to.
So, I am am able to disable the Close button on a docked form on DockPanel-Suite and I am wondering if it would be possible to disable the Auto-Hide button as well. Basically, I am trying to avoid any user to make changes to the layout of the forms on the dock panel. I am able to disable to the close button by this code.
CloseButton = false;
CloseButtonVisible = false;
Is there a similar property that can allow me to disable Auto-Hide button?
If you check pull request #428 at GitHub repo, you can see a proposed commit.
However, my personal opinion is that supporting such magic switches is too much for a project like this. People who don't want certain elements should derive a new theme from existing ones, and manually removing them.
I am working on a WinForms project, and I have a form where I have a DataGrid, a TextBox, and 2 button controls (btnNew and btnSearch). The click event of a btnSearch is supposed to perform a search on the DataGrid.
I deleted the event handler for the search button and have saved my work. It now appears that all other controls have been deleted and the form is back to the default state. The application works fine though when run, with some errors. I have resolved the error but the designer view is still in the default state. How do I go about reinstating my form's design view?
i had your problem and solved it in this way:
just make another form with another name(NewForm.cs) and copy the InitializeComponent() content from YourFirstForm.designer.cs and paste it into
NewForm.designer.cs InitializeComponent() function. but be careful when copy and paste the function content change all YourFirstForm keywords to NewForm . finally Remove YourFirstForm and just work with your NewForm....
With the control selected in the properties window.
Right click on an empty space on the form,
Click cut
Right click / then paste into a cell somewhere in a form control.
I've run into errors like this before where simply closing all the form's files (code view + design view) re-open the code view and then Shift-F7 to reload the design view would fix it.
If that doesn't work perhaps fixing the error you mentioned in the designer view caused something to get out of whack. Try comparing the structure in the YourForm.Designer.cs file with a new form to see if an inadvertent edit was made.
i had your problem in Visual Studio 2017 and solved it in this way:
-select controls by Properties
-view Location is -
-change the Location
-drag the control to another location
Make sure all errors related to form are removed and your code compiles successfully.
If Form has been copied from an existing project make sure Form.Designer.cs and Form.resx are under same parent Form.cs and not separate. Check Form tree in Solution explorer. If they are not under the same tee, load the designer.cs and .resx file again in the project.