Labels and events! - c#

I have a question? How can I wire up an button in a winform to take an input from a label, and put it in a text box to display the result?
I'm confused!
I have 4 labels... I want to be able to have people put input into the labels click the update button, and then display the results in the textbox below.
Any help? Thank you!

OK so basic outline of what you need to do:
1) Go to the toolbox and put textbox(es) on the form for the user to type in.
2) Add at least one label for your output text
3) Add a Button
4) Select each item on the form, go to its properties (f4) and set the Name property for each one to something that you can remember (this is how you'll reference the controls in your code)
5) Double click on the submit button. This will open up an "Event Handler" for Button.Click, which means the code you write will run when someone clicks the button.
6) Write the C# code to do what you want. For instance, this takes the contents of a textbox (tbInput.Text) and copies it to the label text (lblOutput.Text):
lblOutput.Text = tbInput.Text;
Hope this helps...if not, read the first 3 or 4 chapters of any beginning C# book.

You don't put input input into label, you do that in a TextBox. A label is a as its name implies a "label" (fixed unmodifiable text).

Most simply, create a method to handle the Click event of the button, bind it in.
Inside this method get the text from the labels, and then update the textbox with the input.

.NET standard Labels are not the controls you are looking for. Labels are just that...text labels that do not provide for text input. What you want is a TextBox, which you will be able to find in the Visual Studio Toolbox.
If you want the look and feel of a Label, but the functionality of a TextBox, you can modify the TextBox properties accordingly (border style, background color, etc).
Drop a Button onto your form, and from the Designer if you double-click the button, a _Click event handler will be generated in your source file from which you can implement the code to do whatever it is you want to do.

Related

Grab all text inside a container using Selenium c#

I hope someone could help me out on this one. Basically i have this website that has a lot of dialog boxes. These dialog boxes are changed dynamically and they are not any means static content. My task is to grab all the text inside the dialog box, they might be a drop down menu (simple SELECT and OPTION) or it might contain radio button with text beside it, or even checkbox with text beside it etc.. But i need to find a way to GRAB everything inside a container id.
For example: www.facebook.com
The Notification box i only want the text inside that container how would i go about?
It's class id is
"uiScrollableArea fade uiScrollableAreaWithShadow contentAfter contentBefore"
Lets assume for our example the class id is uiScrollableAreaWithShadow.
Thanks.
You can do that by getting the WebElement or Select Object Text
http://selenium.googlecode.com/git/docs/api/java/org/openqa/selenium/WebElement.html
http://selenium.googlecode.com/git/docs/api/java/org/openqa/selenium/support/ui/Select.html

Combobox with checkbox in winforms

I am trying to look for a simple way to design a winform with a combobox that has checkbox values in it to select multiple values.
But there are no free samples I could find.
If anybody has a good link for a sample which does not require a license.
Please let me know.
I am not looking for controls like telerik and infragistics.
Maybe this example can help you.
CheckBox ComboBox Extending the ComboBox Class and Its Items
It sounds like what you really want is a checked listbox control or maybe even just a listbox. These controls do multi-select in a way that is more standard for Windows.
If you really need a combo box with checkboxes in it, here's an article on code project I used once.
My suggestion, if space is an issue as #rmc00 has eluded to, place a button at the end of a readonly Textbox with perhaps an elipse (...) or down arrow (same as combobox) as the text of the button and when clicked or MouseDown make visible and position a CheckBoxList or open a popup dialog with a CheckBoxList this way you can either prepopulate at design time or pass a DataTable as a parameter/property to your control/form so it is databound at runtime. You can always place your control or write code to position the control/form exactly below your TextBox in the MouseDown/Click event. On check change update your textbox with a comma separated list (or go fancy and say if more than 3 items the text box can have the list stored in the Tag and the TextBox Text can have the count of items checked). Finally on LostFocus hide the Control (or Form), and further if you want to get fancy make the exception to not hide when the ActiveControl is the Button that way you can toggle the visibility of consecutive button presses.

WPF: message box with checkbox added

In WPF I am looking for a "do not show again" checkbox on my messagebox popup.
Does anyone know where I can get such a control or maybe how to copy the style of the regular WPF messagebox so I can create my own?
Thanks
Take a look at the Dialog Boxes Overview. The overview covers Message Boxes, Common Dialog Boxes, and Custom Dialog Boxes. In your case you'll want to create a simple Custom Dialog Box that includes a message, a checkbox, and however many buttons you need.
Basically you need to define a new code-behind file that includes your TextBlock, CheckBox, and Buttons in a panel object, and you need to extend Window. In your code-behind file you implement any necessary logic to implement the user's choice, and you return this result to the object containing the custom dialog box.
Make sure to pay special attention to this line of code when creating your custom dialog box:
// Open the dialog box modally
messageBox.ShowDialog();
The call to ShowDialog() will ensure that the user must take action against your dialog box before moving on to other parts of your application.
I think , you may have to create by yourself and it is really easy in the WPF
You could just use a dialog box. An easy way to do it would be to keep a variable in the project settings that would be updated on the popup close() event. So then you would just have to verify the value in the project settings before showing the popup.

Getting handle of Autocomplete dropdown box of textbox in winforms

I wanted to adjust the width of the Autocomplete dropdown box of a textbox. I dont want to adjust the width of that textbox, but only Autocomplete dropdown. I know that there is no way I can increase the width of the Autocomplete dropdown by using properties provided with textbox.
Hence I wanted to know whether there is any way to get the handle of that Autocomplete box and then increase the width of that drop downlist without changing the textbox width?
If this is not possible then I would like to create my custom textbox with autocomplete, in this case how to use the existing autocomplete functionality provided by microsoft? Is there any way to do it. Are there any libraries available for this?
I don't think you can use Microsoft's implementation of autocomplete, which does not have an option to adjust dropdown width.
Create a background thread to not get into the way of typing, and hook up the text change event of a combobox box or a textbox to update the candidate list (assuming autosuggest mode since you mention a dropdown). You can probably add/remove the combobox items on the fly if you have a combobox. But for dropdown list and textbox items you need a popup window
It is easy to get a popup to show, but you need to not use a fixed position so it won't go off the screen when the textbox is close to the edge of the screen. And the focus logic is a little bit complex. you need to keep focus on the textbox unless the user press the arrow keys to make a selection.
so
when focus is on textbox:
arrow keys move the focus to the popup
other keys goes to the textbox, if not handled by the dialog itself, except for the delete key when mouse is over the popup.
when focus is on popup:
arrow keys move the focus to the sibling candidate item or the textbox
other keys goes to the textbox, if not handled by the dialog itself, except for the delete key
mouse clicks:
dismiss the popup outside of the popup or the popup.
update the value of textbox if a candidate item in the popup is clicked on
It takes a lot of effort to get the focus/threading right. If you can afford some form space, you can just add a fixed width listbox to the form instead, like Visual Studio help viewer's index pane.
After going through lot of blog posts and different articles, I came to a consensus that it is next to impossible to get a solution to my problem in the way I wanted. So I've decided either to come up with a custom solution or as Sheng Jiang said I need to implement my own autocomplete object.
I've come up with a solution which fits my requirement by increasing the width of the textbox as per the largest string in the autocomplete string list while I'm adding the autocomplete custom source. As I said I cant increase the width of the text box because of the size constraint on the form, so I decided to keep this textbox in a panel and increase the size of the textbox inside that. Panel will not grow with the textbox so that solved my problem.
I know this is not perfect solution but it fits my requirement.

How to find text in a richtextbox

I have 2 forms. A main one which has a richtextbox on (aswell as other stuff) and another which is used to find text in the richtxtbox on frm1. The second form consists of a textbox for the user to enter the word they are looking for, and 2 buttons. One for Find and one for Find next.
When the find button is selected the found text is highlighted in the main form (neither forms close) and if find next button is clicked the next item is found. (the next button is disabled if there isnt anymore text found)
Now problem is...i dont no how to code this!
You will need to share the textbox with the Find form.
The simplest way to do this is to make the Find form's constructor take a RichTextBox parameter, and pass the textbox to it on the main form.
Then, make a field in the Find form to store the textbox, and set the field to the constructor parameter.

Categories