How to change the panel visibility with richtextbox input - c#

For some reason, this one will not work:
if (richTextBox2.Text == "settings")
panel5.Visible = true;
The other inputs work like "close", inputting close will close the form.
What i want to happen is when "settings" is typed into the text box, i want the panel to become visible.

You could try comparing in this way:
if (richTextBox2.Text.ToUpper() == "SETTINGS")
panel5.Visible = true;
Other way to try, is debug "if" line, and check the content of Text property. Maybe, richTextBox2.Text contains some hidden characters.
I hope this could help you.

Related

How to delete checkbox text from richTextBox using chechked method

Whenever a user click's on the checkBox controls, the text in the checkBox will be appeared on the richTextBox.text and it wasn't so hard because all I needed was :
if (CBSefalexin.Checked == true)
richTextBox1.Text += CBSefalexin.Text;
But now, I want to do something. Whenever user unchecked the checkbox, I want to delete that text (which recently added up to richtextBox.text) from richTextBox. It is obvious that I cannot use the code below:
if (CBSefalexin.Checked == true)
richTextBox1.Text += CBSefalexin.Text;
else
richTextBox1.Text -= CBSefalexin.Text;
Because it's impossible to use "-" for strings. But I want to know if I can write that code in my project. Any suggestion so far ?
Thanks in advance.
UPDATE
I do not want to clean the whole of the text. I just want to delete that specific text which I just added up to richTextBox(Because I have so many checkboxes that I want to do the same things with them)
richTextBox1.Text = richTextBox1.Text.Replace(CBSefalexin.Text,"")
This should replace just the text hat you initially set

Unable to Highlight Text in a TextBox

I have a winforms app that initially displays a window with two file dialog boxes, one folder dialog box, and one textbox with some default text in it. I want the default text to be highlighted. I've tried everything I have found with no luck.
Any advice is appreciated.
Regards.
Make sure HideSelection is false on your textbox and use the select method to select the text:
textBox1.HideSelection = false;
textBox1.Select(0, textBox1.Text.Length);
You can use SelectionStart and SelectionLenght
textbox.SelectionStart = 0;
textbox.SelectionLength = textbox.Text.Length;

Escape TabStop within a WebBrowser control

I'm building a email client in c# that allows users to send HTML emails. I have some general formatting capabilities including the option to insert bulleted and numbered lists. I want to allow users to tab through the controls, but also use the tab key to indent the bullets or numbers in their list. Is there a way to escape TabStop within a certain control, a webBrowser control in particular?
David sparked the idea, but I'd like to give a little more detail. I used mshtml to actually insert the indent and outdent. Just that still moved to the next control, so adding e.IsInputKey = true actually kept the cursor in the webBrowser control so the user can continue typing.
private void webBrowser_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
{
if (e.KeyData == Keys.Tab)
{
webBrowser.Document.ExecCommand("Indent", false, null);
e.IsInputKey = true; //prevents going to next control
}
else if (e.KeyData == (Keys.Shift | Keys.Tab))
{
webBrowser.Document.ExecCommand("Outdent", false, null);
e.IsInputKey = true;
}
}
For a multiline TextBox you can use the AcceptsTab property.
For a WebBrowser control I think you have to use the KeyPress event and insert a tab character \t yourself.

control to show steps to do something in winforms

i want to show steps on how to cook something in winform c# .net as steps. Something like a set of text area would be nice but:
-> list box considers the whole string of one step as one item so user needs to scroll horizontally to view the whole step.
-> datagridview is also not suitable as i want the text to word wrapped.
i also want the user to be able to edit the step.
any suggestions of custom control would be nice.
Maybe a wizard like app would be suitable for you. AFAIK there's no native wizard control in C# but you could implement one using tabs or using one of many in the web.
A multi line text box will do the job great. just take a simple text box and do the following to it, and it will turn to a text area:
TextBox listBoxNewInput = new TextBox();
//Initialize label's property
listBoxNewInput.Multiline = true;
// Add vertical scroll bars to the TextBox control.
listBoxNewInput.ScrollBars = ScrollBars.Vertical;
// Allow the RETURN key in the TextBox control.
listBoxNewInput.AcceptsReturn = true;
// Allow the TAB key to be entered in the TextBox control.
listBoxNewInput.AcceptsTab = true;
// Set WordWrap to true to allow text to wrap to the next line.
listBoxNewInput.WordWrap = true;
listBoxNewInput.Width = 315;
listBoxNewInput.Height = 150;
listBoxNewInput.DoubleClick += new EventHandler(listBoxNewInput_DoubleClick);
flowLayoutPanel1.FlowDirection = FlowDirection.TopDown;
flowLayoutPanel1.Controls.Add(labelInput);
flowLayoutPanel1.FlowDirection = FlowDirection.TopDown;
flowLayoutPanel1.Controls.Add(list
BoxNewInput);

Multiline text as the button label in Windows Forms

Basically, I am creating a button in an oval shape. But my button label is too long to display in one line, so I wanted to split it into multiple lines so that the oval button looks good.
How do I enable word wrap on a button?
If you want to set a button's label to multi-line text inside the VS designer, you can click on the "down arrow" at the right of the property field and then you are able to enter multiple lines of text.
I tried this in VS 2015.
Set the label text on form load and add Environment.Newline as the newline string, like this:
btnOK.Text = "OK" + Environment.NewLine + "true";
Just add a newline in the text at the place where it should split.
Try to add "\n" to button's Text property in the places you want to wrap.
There are two options:
If you are creating a custom control, then place a label control on it with the Autosize = true option. And adjust its size as per the buttons size.
Add a new line wherever you want (a bit crude).
You can create custom Button with one additional property (say, Label) which converts "\n" occurrence into "real" newline (because VS designer cannot do it already 10 years):
public string Label
{
get { return (string.IsNullOrEmpty(Text) ? Text : Text.Replace("\n", #"\n")); }
set {
Text = (string.IsNullOrEmpty(value) ? value : value.Replace(#"\n", "\n"));
}
}
Once you created such class, your SuperButton will be visible in Toolbox at Project page, so you don't loose visual way of design.
You just need to insert a line break (i.e. \n) in the button text.
Example:
Button1.AutoSize = true;
Button1.Text = "This is \n The Button Text";

Categories