Which textbox event will generate an email when the textbox is clicked? - winforms

All I want to do is input a Forename and a Surname into two textboxes and in the Email textbox generate an email address using the forename and surname. It isn't hard at all but none of the events I've tried have worked. I've even dummed it down so that if any of the events happen the email textbox should just say "hello".
None of these event have worked:
private void EmailAddressInputTextbox_TextChanged(object sender, EventArgs e)
{
EmailAddressInputTextbox.Text = ("Hello");
}
private void EmailAddressInputTextbox_GotFocus(object sender, EventArgs e)
{
EmailAddressInputTextbox.Text = ("Hello");
}
private void EmailAddressInputTextbox_Enter(object sender, EventArgs e)
{
EmailAddressInputTextbox.Text = ("Hello");
}
private void EmailAddressInputTextbox_Click(object sender, EventArgs e)
{
EmailAddressInputTextbox.Text = ("Hello");
}
Even tried:
private void SurnameInputTextbox_Leave(object sender, EventArgs e)
{
EmailAddressInputTextbox.Text = ("Hello");
}
Ideally I want the textbox to be filled when it has been clicked on and can be typed in but so far nothing happens...

Related

Caching Cookies in Awesomium

The Setup:
I am building an MDI Application. One of the Child Forms I call is a basic web browser using the Awesomium API.
Reference: BrowserControl.cs
public partial class BrowserControl : UserControl
{
public BrowserControl()
{
InitializeComponent();
}
private void OnControlLoad(object sender, EventArgs e)
{
String w3DataPath = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location) + "\\HttpAgent";
if (!Directory.Exists(w3DataPath))
{
Directory.CreateDirectory(w3DataPath);
}
var webSession = WebCore.CreateWebSession(w3DataPath, WebPreferences.Default);
webControl.WebSession = webSession;
}
private void OnBackButtonClick(object sender, EventArgs e)
{
this.webControl.GoBack();
}
private void OnFwdButtonClick(object sender, EventArgs e)
{
this.webControl.GoForward();
}
private void OnReloadButtonClick(object sender, EventArgs e)
{
this.webControl.Reload(true);
}
private void OnStopButtonClick(object sender, EventArgs e)
{
this.webControl.Stop();
}
private void OnHomeButtonClick(object sender, EventArgs e)
{
this.webControl.GoToHome();
}
private void OnSearchButtonClick(object sender, EventArgs e)
{
String urlString = String.Format("https://www.google.com/#q={0}", HttpUtility.UrlEncode(this.SearchBox.Text));
this.webControl.Source = new System.Uri(urlString);
}
private void OnLoadingFrame(object sender, Awesomium.Core.LoadingFrameEventArgs e)
{
this.BrowserStatus.Text = "Loading " + e.Url;
}
private void OnLoadingComplete(object sender, Awesomium.Core.FrameEventArgs e)
{
this.BrowserStatus.Text = "Document Ready";
}
private void OnLoadingFailure(object sender, Awesomium.Core.LoadingFrameFailedEventArgs e)
{
this.BrowserStatus.Text = e.ErrorDescription;
}
}
Problem: Functionally the browser works just fine; however, it does not cache any persistent data locally. Note, I have established a valid DataPath using the Awesomium WebSession object as indicated in the above method OnControlLoad()
In terms of the validity of the path I define - I have confirmed it does exist on disk and it even appears the Awesomium WebSession adds a sub-directory called "cache". Unfortunately, none of the cookies I am getting in my web session are being saved locally. In fact - nothing is being cached. Both the HttpAgent directory I define and the cache directory the WebSession object defines are empty after deliberately logging into sites I know set cookies.
Any insight or help would be greatly appreciated. Thanks
I am not sure if it helps but try closing Awesomium "correctly": dispose WebControls, WebSession, call WebCore.Shutdown().

changing datagridview selection color dynamically c#

the problem is that when i change the color of selected row by RowTemplate.DefaultCellStyle.SelectionBackColor in my form constructor it works but it does not work in button events when user clicks some button for changing grid selected back color!
any help please!
public Form1()
{
InitializeComponent();
dataGridView1.RowTemplate.DefaultCellStyle.SelectionBackColor=Color.Red; //this works fine
}
void button2_Click(object sender, EventArgs e)
{
dataGridView1.RowTemplate.DefaultCellStyle.SelectionBackColor=Color.Blue;//but this does not work
}
Try this ..
void dataGridView1_RowPrePaint(object sender,
DataGridViewRowPrePaintEventArgs e)
{
If (DatagridView1.Rows(DataGridView1.CurrentCell.RowIndex).Selected )
{
DataGridView1.Rows(DataGridView1.CurrentCell.RowIndex).DefaultCellStyle.SelectionBackColor=Color.Blue;
}
}
void button2_Click(object sender, EventArgs e)
{
foreach (DataGridViewRow row in dataGridView1.Rows)
{
row.DefaultCellStyle.SelectionBackColor = Color.Blue
}
}
Update :
void button2_Click(object sender, EventArgs e)
{
foreach (DataGridViewColumn col in dataGridView1.Columns)
{
col.DefaultCellStyle.BackColor = Color.Blue
}
}

Mouse click and drag Event WPF

I am developing an analog clock picker control.
The user is able to click on the minute or hour hand and drag to turn the needle to select the specific time. I was wondering how to detect such a click and drag event.
I tried using MouseLeftButtonDown + MouseMove but I cannot get it to work as MouseMove is always trigger when the mousemove happen despite me using a flag. Is there any easier way?
public bool dragAction = false;
private void minuteHand_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
dragAction = true;
minuteHand_MouseMove(this.minuteHand, e);
}
private void minuteHand_MouseMove(object sender, MouseEventArgs e)
{
if (dragAction == true)
{
//my code: moving the needle
}
}
private void minuteHand_MouseLeftButtonUp(object sender, MouseEventArgs e)
{
dragAction = false;
}
I think this is the easiest and most straightforward way :
private void Window_MouseMove(object sender, MouseEventArgs e) {
if (e.LeftButton == MouseButtonState.Pressed) {
this.DragMove();
}
}
public bool dragAction = false;
private void minuteHand_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
dragAction = true;
minuteHand_MouseMove(this.minuteHand, e);
}
private void minuteHand_MouseMove(object sender, MouseEventArgs e)
{
if (dragAction == true)
{
this.DragMove();
}
}
private void minuteHand_MouseLeftButtonUp(object sender, MouseEventArgs e)
{
dragAction = false;
}
does the trick
You can make things easier and need not handle mouse down / up :
private void minuteHand_MouseMove(object sender, MouseEventArgs e)
{
if (Mouse.LeftButton == MouseButtonState.Pressed)
{
//my code: moving the needle
}
}

Create WPF TextBox that accepts only Text

private void txtLastName_PreviewKeyDown(object sender, KeyEventArgs e)
{
if (!char.IsDigit((char)e.Key)) e.Handled = true;
}
But It not support all key in keyboard .
private void txtLastName_PreviewTextInput(object sender, TextCompositionEventArgs e)
{
if (!System.Text.RegularExpressions.Regex.IsMatch(e.Text, "^[a-zA-Z]"))
{
e.Handled = true;
}
}
You must use IsLetter.
private void txtLastName_PreviewKeyDown(object sender, KeyEventArgs e)
{
if (Char.IsLetter((char)e.Key)) e.Handled = true;
}
This thread is really old, but if someone still needs it, here is code that is working for me
(Edited a little bit Usman's code)
private void TextValidationTextBox(object sender, TextCompositionEventArgs e)
{
Regex regex = new Regex("[^a-zA-Z]+");
e.Handled = regex.IsMatch(e.Text);
}
And don't forget to put code below to TextBox that you want to accept only text ( in xaml )
PreviewTextInput="TextValidationTextBox"

How do I display a tooltip when focus is in a specific textbox?

For a textbox, I want to display a tooltip immediatly when the focus is in on the textbox, and stay there for the duration of the focus - not just when the mouse hovers over the textbox.
How can I do that?
The Enter and Leave events are probably useful here, and show it with a duration of 0 to keep it there.
private ToolTip tt;
private void textBox1_Enter(object sender, EventArgs e) {
tt = new ToolTip();
tt.InitialDelay = 0;
tt.IsBalloon = true;
tt.Show(string.Empty, textBox1);
tt.Show("I need help", textBox1, 0);
}
private void textBox1_Leave(object sender, EventArgs e) {
tt.Dispose();
}
Note: Calling the Show(...) method twice like in my example will force the "pointer" to point correctly to the control.
have tested, the event names:
private void textbox_Enter(object sender, EventArgs e)
{
toolTip1.Show("your tip here", textbox);
}
private void textbox_Leave(object sender, EventArgs e)
{
toolTip1.Hide(textbox);
}
tooltip is a control, needs to be added from toolbox.
using mouse hover and mouse leave events
private void textBox1_MouseHover(object sender, EventArgs e)
{
toolTip1.Show("your tip here", textBox2);
}
private void textBox1_MouseLeave(object sender, EventArgs e)
{
toolTip1.Hide(textBox2);
}
>
Windows Forms
public partial class FormWindow : Form
{
//Constructor
public FormWindow()
{
txtUrl.Text = "Enter text here";
txtUrl.ForeColor = Color.Gray;
txtUrl.GotFocus += TxtUrl_GotFocus;
txtUrl.LostFocus += TxtUrl_LostFocus;
}
private void TxtUrl_GotFocus(object sender, EventArgs e)
{
txtUrl.Text = "";
txtUrl.ForeColor = Color.Black;
}
private void TxtUrl_LostFocus(object sender, EventArgs e)
{
if (string.IsNullOrWhiteSpace(txtUrl.Text))
{
txtUrl.Text = "Enter text here";
txtUrl.ForeColor = Color.Gray;
}
}
}
Use a System.Windows.Forms.ToolTip and show it in textbox GotFocus event and Hide it in LostFocus event:
void textBox_GotFocus(object sender, EventArgs e)
{
toolTip.Show("your tip", textBox);
}
void textBox_LostFocus(object sender, EventArgs e)
{
toolTip.Hide(textBox);
}

Resources