[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

[Solved] How to cache the image of the control?

This will help: Bitmap getControlSurface(Control ctl) { bitmap = new Bitmap(ctl.Width, ctl.Height); using (Graphics g = Graphics.FromImage(bitmap)) { Point pScreen = PointToScreen(ctl.Location); g.CopyFromScreen(pScreen, Point.Empty, ctl.Size); } return bitmap; } If you know when the surface has been refreshed you can use it like this: if ( pictureBox1.Image != null) pictureBox1.Image.Dispose(); pictureBox1.Image = getControlSurface(pictureBox1); The only … Read more

[Solved] Winforms owner-drawn controls and resizing

Solved (for anyone else owner-drawing controls): protected override void WndProc(ref Message m) { const int WM_WINDOWPOSCHANGED = 0x0047; base.WndProc(ref m); if (m.Msg == WM_WINDOWPOSCHANGED) { //Make changes to your display rectangle here… this.PerformLayout(); } } solved Winforms owner-drawn controls and resizing

[Solved] Alert on Closing window in Window Form Application in C# [duplicate]

You can find this by a simple search! Handle Closing event of your form: this.Closing += OnClosing; // For example put this in the constructor of your form private void OnClosing(object sender, CancelEventArgs cancelEventArgs) { string msg = “Do you want to close this?”; DialogResult result = MessageBox.Show(msg, “Close Confirmation”, MessageBoxButtons.YesNo/*Cancel*/, MessageBoxIcon.Question); if (result == … Read more