When I implement auto-complete in textbox1 the usual way, I can complete only one word before auto-complete stops. For example, I have these items added to the auto-complete list (accessible from designer/GUI):
{ "print",
"messagebox",
"disassemble",
"virusscan",
"system.securitywarning" }
If I type "pr," I get print then that's it. How can I make the auto-complete feature continue with every space so that I can do:
I type "pr"
It auto-completes it as "print"
I press "space"
I type "system.secur"
It auto-completes it as "system.securitywarning"
I would really appreciate it if anyone can help :)
Related
recently moved over to visual studio
When I start typing a word, let's say "Tex" I get the popup with possible auto-fillings, and if I press enter, it automatically changes it to "TextBox"
The problem I have is, whenever I do that, I have to press 'space' to start typing the next word, something that get's pretty annoying if you type 10,000 words..
Is there an easy way to make the typing start one space after the autofilled word?
Thank you in advance :)
Pic1: http://prntscr.com/fbpzdq
Pic2: http://prntscr.com/fbpzlc
Yes, you can simply use the Spacebar to perform the auto-complete instead of pressing Enter. Both methods finish the completion of the word, but using the Spacebar will also add a space after the word.
It even works when using the "." character after a name; you still get the intellisense list of object members to choose from, and auto complete will magically remove the space(s) when you type a ; or closing brace }, or any other character that triggers line formatting.
Example
// This is what it looks like while typing, using Spacebar to complete the words
this .textBox1 .Text = "hello"
// And then as soon as the `;` is added, it's all fixed:
this.textBox1.Text = "hello";
And, for what it's worth, whitespace is allowed on either side of the . between an object and it's members. So even if the spaces were left as in the first example, the code still compiles and runs just fine.
I want to be able to type auto-property without such effect (inserting new line after I type ;):
This only occurs if intellisence shows its suggestions. Pressing Esc just before pressing ; helps (suggestion popup disappears and new line is not inserted), but it seems impossible to remember, I constantly fail.
Is there a way to remove that weird "new line" behavior? I don't remember such in previous VS.
Try this way:
Type: prop
Press tab 2 times
Change property type if needed
Press tab
Enter property name
You are done!
I'm very new to C# and I'm trying to make a simple GUI hangman game to help me learn. I am using a textbox to both output errors (The letter was already entered. Try again) etc. and input the user's guess. However my problem comes in that whenever the user is given an error, they have to manually clear the textbox. What I'm looking for is a feature in most search boxes, google for example, that clears (in google's case, highlights) the text currently in the box.
I know it can be simply done using
textboxname.Clear();
but I'm not sure where it should go, I can place it under the code for a button without a problem but my instinct is to put it outside of the button's {} , however when I try this the text box isn't recognized and if statements can't be used.
I think I'm looking for:
if (TextBoxName.Focus)
{
TextBoxName.Clear();
}
But I'm just not sure where to put it
I am sure that the answer to this has been posted before. Forgive me as I think I am just not thinking of the right search string.
What I have is a context menu strip assigned to my tray icon for my dialer. The idea is for the user to set various numbers and select the user defined numbers from the menu and initiate the dial.
So the menu pops up with Presets, Setup, & Exit. I want the Presets menu to open a new tree listing the user defined number. I also want this to populate from an xml file every time the application is loaded.
My problem is that I have no idea how to dynamically populate a sub menu item and give it a function.
So how would I at start up add user defined numbers to preset -> (userNumber1, usernumber2, userNumber3) and then call the dial() function when clicked?
So I found how to add to the list... I now feel silly for asking that. For anyone else who wants to know that one, The list item is given a name. Im my case the name attribute is " presetsToolStripMenuItem"
So to add an item to it call the name
presetsToolStripMenuItem.DropDownItems.Add(string text)
No to move on. I am stuck now trying to figure out how to assign an event to that newly added function. I did find
presetsToolStripMenuItem.DropDownItems.Add(string text, image, eventargs)
I am struggling with this one. Maybe I need to stop and come back to it later. Perhaps if someone could provide me with an example of using this line to call a function(); I would be most appreciative.
For anyone that is interested I figured out the solution to adding a context menu item at run time with the ability to call a function.
As stated before, to add a sub menu item to a a parent category, use the parent.name. So in my case the preset menu item name was "presetsToolStripMenuItem"
To add function I used the 3 argument method.
ToolStripMenuItem.DropdownItems.Add("string name", image, eventargs);
so my code looks like this:
presetsToolStripMenuItem.DropDownItems.Add("added2", null, disp);
void disp(object sender, EventArgs e)
{
MessageBox.Show("It works!");
}
Just out of being bored, I decided to start building my own text editor. I have been having trouble with my coding, so my teacher had suggested building smaller programs that I wanted to write to help get me more familiar with the language, and since I couldn't think of anything, I ended up making this text editor.
I've been trying to root through the code on my own as much as possible, but I was wondering how to make the text that appears at the top of the form (beside the icon) reflect the current filename (or "new" or something if there is no file loaded) as well as having the * if the file has been edited.
I would also like to know how to code my exit button to check if the text has been edited before closing, and ask the user to save if it has, as well as having this show up if the user uses the "X" button in the corner, which currently flat out exits the program no matter what.
To change the title (text besides the icon):
Form1.Text = "This is a new title";
where Form1 is the name of you form object
To check if text is saved:
Hold a boolean variable that indicates whether the user saved the text or not.
Use the Form_Closing method to check if this variable is set to true, and do as you wish
More on Form_Closing here
Many questions :)
Let me answer a few of them:
In your own code, you should probably set a "dirty bit". In other words, declare a boolean variable that says whether or not the text changed. "Changed" is something you, the programmer, needs to define. It can mean many different things - you get to decide.
Each Winform "control" has a set of "properties", most of which you can change programmatically (on-the-fly). Your "form" has a "text" property that changes the title. Label, Button and other controls also have their own "text" property you can change at will.
Each Winform control also has a set of "events" you can override. The "Close" event is the easiest way to manage program shutdown - including if somebody pressed the "X" button. This is also a good place to check your "dirty bit", and save the file accordingly.