[Solved] Time string to a different DateTime format in c# [closed]

Assuming timeDeparture.Text has Format h:mm tt like 9:10 pm, you have to parse it first into DateTime and use .ToString() to bring it into the desired 24h format. In .NET h is for 12h format and H represents 24h format. string timeDeparture = “10:30 PM”; DateTime parsedResult = DateTime.ParseExact(timeDeparture, “h:mm tt”, System.Globalization.CultureInfo.InvariantCulture); string result = … Read more

[Solved] Is it possible to create a dialog which only blocks its parent? [closed]

You can disable the opening Form instead of making the modal child truly modal.. You can try this: Open the ‘modal’ children with this.Enabled = false; FormDlg yourModalChildForm= new FormDlg(this); yourModalChildForm.Show(); In the constructor write : Form myParent; public FormDlg(Form myParent_) { InitializeComponent(); myParent = myParent_; } And in the FormClosed write: private void FormDlg_FormClosed(object … Read more

[Solved] Textbox into Label [closed]

Here label1 is a Label That you placed in the UI, And you are trying to assign a string value to that control. Such assignment is not valid and not permitted. Your requirement is to assign alPos as the Text property of the Label Control. So your query should be like the following: label1.Text = … Read more

[Solved] Rename a checkbox by implementing ContextMenu c# winforms [closed]

I have got the answer. private void MenuViewDetails_Click(object sender, EventArgs e) { // Try to cast the sender to a MenuItem MenuItem menuItem = sender as MenuItem; if (menuItem != null) { // Retrieve the ContextMenu that contains this MenuItem ContextMenu menu = menuItem.GetContextMenu(); // Get the control that is displaying this context menu Control … Read more

[Solved] Entering value to database after pressing enter from a textbox [closed]

Use for this KeyDown event private void YourTextBox_KeyDown(object sender, KeyEventArgs e) { String connection= “Data Source=YourServer;Initial Catalog=YourDatabase;user=User;password=YourPassword;Integrated Security=True;”; if (e.KeyCode == Keys.Enter) { string insertCmdText = “INSERT INTO table(column1)values(@valueForColumn1)”; SqlCommand sqlCom = new SqlCommand(insertCmdText,connection); sqlCom.Paramaters.AddWithValue(“@valueForColumn1”,YourTextBox.Text); connection.Open(); sqlCom.ExecuteNonQuery(); connection.Close(); } } But consider that saving into Database after KeyPress event is not a right way to … Read more

[Solved] C# Windows Form – access code [closed]

You can access the Control’s objects attributes by it’s name. For example: NumericUpDown1 <- It’s the name of your Control In your C# code you can access all of it’s attribtes and methods by puttin a period after it’s name: NumericUpDown1.Maximun = 100; NumericUpDown1.Width = 250; NumericUpDown1.Height = 10; etc. You can serach it by … Read more