I'm using Visual Studio 2010 to create an application. I have a class derived from the System.Windows.Forms.Form control. This class, called CViewport, is a standard for all forms in my application( ie. I intend to derive other forms from this class).
After deriving a class from CViewport, I go to the designer to edit the 2nd generation form and in the designer the form is not displayed correctly. It appears transparent if I'm not mistaken...the previous window shines through the client area of the form as if the backbuffer has not been drawn to by the designer...
...Also, after changing the size of the 2nd gen form, the designer resets the size to arbitrary dimensions...
Why might this be happening? Here is Form derived class:
namespace MyApp
{
public partial class CViewport : Form
{
public CViewport()
{
InitializeComponent();
}
}
}
here is CViewport.Designer.cs:
namespace MyApp
{
partial class CViewport
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(GDEViewport));
this.SuspendLayout();
//
// CViewport
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(800, 600);
this.ControlBox = false;
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.Sizable;
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "GDEViewport";
this.ShowIcon = false;
this.ShowInTaskbar = false;
this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Hide;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
this.Activated += new System.EventHandler(this.ViewportForm_Activated);
this.Deactivate += new System.EventHandler(this.ViewportForm_Deactivate);
this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.OnFormClosing);
this.ResizeBegin += new System.EventHandler(this.ViewportForm_ResizeBegin);
this.ResizeEnd += new System.EventHandler(this.ViewportForm_ResizeEnd);
this.Paint += new System.Windows.Forms.PaintEventHandler(this.ViewportForm_Paint);
this.Resize += new System.EventHandler(this.MainViewport_UserResized);
this.ResumeLayout(false);
}
#endregion
}
}
here is 2nd gen form derived from CViewport
namespace MyApp
{
public partial class CMainViewport: CViewport
{
public CMainViewport()
{
InitializeComponent();
}
}
}
here is CMainViewport.Designer.cs:
namespace MyApp
{
partial class CMainViewport
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.SuspendLayout();
//
// CMainViewport
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(1218, 573);
this.ControlBox = true;
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.Sizable;
this.MaximizeBox = true;
this.MinimizeBox = true;
this.MinimumSize = new System.Drawing.Size(800, 600);
this.Name = "TestForm";
this.RightToLeft = System.Windows.Forms.RightToLeft.No;
this.ShowIcon = true;
this.ShowInTaskbar = true;
this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Auto;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "TestForm";
this.PauseRendering += new System.EventHandler<System.EventArgs>(this.ViewportForm_PauseRendering);
this.ResumeRendering += new System.EventHandler<System.EventArgs>(this.ViewportForm_ResumeRendering);
this.SystemResume += new System.EventHandler<System.EventArgs>(this.MainViewport_SystemResume);
this.SystemSuspend += new System.EventHandler<System.EventArgs>(this.MainViewport_SystemSuspend);
this.UserResized += new System.EventHandler<System.EventArgs>(this.MainViewport_UserResized);
this.Activated += new System.EventHandler(this.ViewportForm_Activated);
this.Deactivate += new System.EventHandler(this.ViewportForm_Deactivate);
this.ResizeBegin += new System.EventHandler(this.ViewportForm_ResizeBegin);
this.ResizeEnd += new System.EventHandler(this.ViewportForm_ResizeEnd);
this.Paint += new System.Windows.Forms.PaintEventHandler(this.ViewportForm_Paint);
this.Resize += new System.EventHandler(this.ViewportForm_Resize);
this.ResumeLayout(false);
}
#endregion
}
}
this.ResizeBegin += new System.EventHandler(this.ViewportForm_ResizeBegin);
this.ResizeEnd += new System.EventHandler(this.ViewportForm_ResizeEnd);
this.Paint += new System.Windows.Forms.PaintEventHandler(this.ViewportForm_Paint);
this.Resize += new System.EventHandler(this.MainViewport_UserResized);
The designer runs the code in the base class to provide the WYSIWYG view. That's normally the Form class, it doesn't have any bugs. Now it is your CViewPort class. It has bugs. In one those event handlers that we cannot see.
Like the Paint event handler, strong lead to "is not displayed correctly". You have a handler for Resize, strong lead to "resets the size to arbitrary dimensions". Having these events also run at design time is what is getting you into trouble. And you are doing it wrong, a base class for a Form should override OnPaint() and OnResize() so the order in which code runs is predictable and controllable.
Having code run at design-time requires deeper insight in the way Winforms works, getting guidance from a book is rather important. You are not there yet, you didn't realize that posting the code for these event handlers was even relevant. There's a keep-out-of-trouble approach that gives you time to read the book, add this line of code to every event handler you added to your CViewPort class:
if (this.DesignMode) return;
The answer posted by Hans Passant was very helpful...the problem though, was that I was setting the DockStyle property of the base class to 'Fill' in the base form's constructor. Removing this line of code fixed the problem...
Related
For instance, if there is a push button, when the user press the button, the system should detect and record the time in dd-mm-yy. However, if the user press the button many time in 2 second, the system should only record the first time when the user press the button.
Assumption: you want to collect clicks but no more often than every 2 seconds. This simple form will do it.
Code:
namespace RecordClicks {
public partial class Form1 : Form {
private DateTime _recordedClick = DateTime.MinValue;
public Form1() {
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e) {
DateTime currentClickTime = DateTime.Now;
if (currentClickTime.Subtract(_recordedClick).TotalMilliseconds > 2000 ) {
_recordedClick = currentClickTime;
lblClick.Text = currentClickTime.ToString();
// TODO: add code to record this click
}
}
}
}
Designer:
namespace RecordClicks {
partial class Form1 {
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing) {
if (disposing && (components != null)) {
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent() {
this.button1 = new System.Windows.Forms.Button();
this.lblClick = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// button1
//
this.button1.Location = new System.Drawing.Point(121, 241);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(132, 53);
this.button1.TabIndex = 0;
this.button1.Text = "Clicker";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// lblClick
//
this.lblClick.AutoSize = true;
this.lblClick.Font = new System.Drawing.Font("Segoe UI", 24F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
this.lblClick.Location = new System.Drawing.Point(121, 127);
this.lblClick.Name = "lblClick";
this.lblClick.Size = new System.Drawing.Size(90, 45);
this.lblClick.TabIndex = 1;
this.lblClick.Text = "Time";
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(800, 450);
this.Controls.Add(this.lblClick);
this.Controls.Add(this.button1);
this.Name = "Form1";
this.Text = "Clicker Test";
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private Button button1;
private Label lblClick;
}
}
I'm working on two C# winforms and WPF applications that utilize the iTunes COM and have noticed some peculiar behavior accessing the PlayerPositionMS property, which is the player's position in milliseconds. The precision of the PlayerPositionMS value is dependent on whether or not the iTunes application has focus or not. The goal for my 2 apps would be to update the player position with the most accuracy. Any assistance would be appreciated.
Below is some sample code to illustrate my point. This is a winforms application with a single label and timer. The timer interval is the default 100 milliseconds, and the tick method updates the label text with the PlayerPositionMS property value. When iTunes has focus the label is updated as expected. But when the winforms application, or anything else, has focus the label is updated roughly every second. The behavior is the same on winforms and WPF.
iTunes version: 12.9.0.167
iTunesLib version: 1.13
Form snip:
Form code:
namespace Test
{
partial class Form_Test
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.label_Position = new System.Windows.Forms.Label();
this.timer_Test = new System.Windows.Forms.Timer(this.components);
this.SuspendLayout();
//
// label_Position
//
this.label_Position.AutoSize = true;
this.label_Position.Location = new System.Drawing.Point(12, 9);
this.label_Position.Name = "label_Position";
this.label_Position.Size = new System.Drawing.Size(16, 13);
this.label_Position.TabIndex = 0;
this.label_Position.Text = "---";
//
// timer_Test
//
this.timer_Test.Enabled = true;
this.timer_Test.Tick += new System.EventHandler(this.UpdateLabel);
//
// Form_Test
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(205, 33);
this.Controls.Add(this.label_Position);
this.Name = "Form_Test";
this.Text = "Test Form";
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.Label label_Position;
private System.Windows.Forms.Timer timer_Test;
}
}
Code behind:
using iTunesLib;
using System;
using System.Windows.Forms;
namespace Test
{
public partial class Form_Test : Form
{
private static iTunesApp _itunes = new iTunesLib.iTunesApp();
public Form_Test()
{
InitializeComponent();
}
private void UpdateLabel(object sender, EventArgs e)
{
if (_itunes.CurrentTrack != null && _itunes.PlayerState == ITPlayerState.ITPlayerStatePlaying)
label_Position.Text = _itunes.PlayerPositionMS.ToString();
}
}
}
Calling the Resume method before accessing the PlayerPositionMS property seems to work to resolve this:
private void UpdateLabel(object sender, EventArgs e)
{
if (_itunes.CurrentTrack != null && _itunes.PlayerState == ITPlayerState.ITPlayerStatePlaying)
{
_itunes.Resume();
label_Position.Text = _itunes.PlayerPositionMS.ToString();
}
}
I have an issue with C# richtextbox and Microsoft equation editor. My goal is to read, modify and save changes in rtf file.
I followed tutorial below:
C# Tutorial : How to insert Math Equation to RichTextBox | FoxLearn
I can read and modify equation in editor, however I can't update richtextbox after modification, modified value is not changed in richtboxtext.
Initial state
Modification
Update(F3) and exit in equation editor doesn't cause change in richtextbox.
However when I double click equation in editor there is changed value.
Here is my code:
using System;
using System.Windows.Forms;
namespace Panel.Views
{
public partial class Axis : Form
{
public Axis()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
richTextBox1.SelectedRtf = Panel.Properties.Resources.Plot1_x_axis;
}
}
}
namespace Panel.Views
{
partial class Axis
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.button1 = new System.Windows.Forms.Button();
this.richTextBox1 = new System.Windows.Forms.RichTextBox();
this.SuspendLayout();
//
// button1
//
this.button1.Location = new System.Drawing.Point(723, 431);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(75, 23);
this.button1.TabIndex = 0;
this.button1.Text = "button1";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// richTextBox1
//
this.richTextBox1.Location = new System.Drawing.Point(28, 36);
this.richTextBox1.Name = "richTextBox1";
this.richTextBox1.Size = new System.Drawing.Size(770, 372);
this.richTextBox1.TabIndex = 1;
this.richTextBox1.Text = "";
//
// Axis
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(822, 478);
this.Controls.Add(this.richTextBox1);
this.Controls.Add(this.button1);
this.Name = "Axis";
this.Text = "Axis";
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.Button button1;
private System.Windows.Forms.RichTextBox richTextBox1;
}
}
I would be appreciated for any help, hints or suggestions how to solve this issue.
Thank you in advance.
I am developing a windows forms application for Windows Mobile 6 in Visual Studio 2008. There is a requirement to have some common controls on each form, such as Logo (PictureBox), Title (Label) and a small description (also Label). I decided to make a FormBase with those controls and inherit other forms from that base.
The problem is that for some reason, when I drop a Button or another control on that inherited form, I cannot resize it with my mouse. I can press Shift+Arrow to resize anything with my keyboard shortcuts, but the mouse does not work.
It's not very convenient neither for me nor for other developers in my team.
Any suggestions?
Update 1
the base form:
public class FormBase : Form
{
public FormBase()
{
InitializeComponent();
}
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FormBase));
this.pictureLogo = new System.Windows.Forms.PictureBox();
this.labelTitle = new System.Windows.Forms.Label();
this.panelSeparator = new System.Windows.Forms.Panel();
this.SuspendLayout();
//
// pictureLogo
//
this.pictureLogo.Image = ((System.Drawing.Image)(resources.GetObject("pictureLogo.Image")));
this.pictureLogo.Location = new System.Drawing.Point(0, 0);
this.pictureLogo.Name = "pictureLogo";
this.pictureLogo.Size = new System.Drawing.Size(48, 48);
//
// labelTitle
//
this.labelTitle.Font = new System.Drawing.Font("Tahoma", 10F, System.Drawing.FontStyle.Bold);
this.labelTitle.ForeColor = System.Drawing.Color.Black;
this.labelTitle.Location = new System.Drawing.Point(54, 2);
this.labelTitle.Name = "labelTitle";
this.labelTitle.Size = new System.Drawing.Size(183, 16);
this.labelTitle.Text = "Title";
//
// panelSeparator
//
this.panelSeparator.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.panelSeparator.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(35)))), ((int)(((byte)(44)))), ((int)(((byte)(75)))));
this.panelSeparator.Location = new System.Drawing.Point(3, 50);
this.panelSeparator.Name = "panelSeparator";
this.panelSeparator.Size = new System.Drawing.Size(234, 1);
//
// FormBase
//
this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi;
this.AutoScroll = true;
this.BackColor = System.Drawing.Color.White;
this.ClientSize = new System.Drawing.Size(240, 320);
this.ControlBox = false;
this.Controls.Add(this.panelSeparator);
this.Controls.Add(this.labelTitle);
this.Controls.Add(this.pictureLogo);
this.ForeColor = System.Drawing.Color.Black;
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
this.KeyPreview = true;
this.Location = new System.Drawing.Point(0, 0);
this.MinimizeBox = false;
this.Name = "FormBase";
this.Text = "FormBase";
this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.PictureBox pictureLogo;
private System.Windows.Forms.Label labelTitle;
private System.Windows.Forms.Panel panelSeparator;
}
the inherited form:
public class FrontDoorForm : FormBase
{
public FrontDoorForm()
{
InitializeComponent();
}
private void buttonQuit_Click(object sender, EventArgs e)
{
Close();
}
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.buttonQuit = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// buttonQuit
//
this.buttonQuit.Location = new System.Drawing.Point(3, 54);
this.buttonQuit.Name = "buttonQuit";
this.buttonQuit.Size = new System.Drawing.Size(115, 46);
this.buttonQuit.TabIndex = 2;
this.buttonQuit.Text = "Quit";
this.buttonQuit.Click += new System.EventHandler(this.buttonQuit_Click);
//
// FrontDoorForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi;
this.BackColor = System.Drawing.Color.White;
this.ClientSize = new System.Drawing.Size(240, 320);
this.Controls.Add(this.buttonQuit);
this.Font = new System.Drawing.Font("Tahoma", 10F, System.Drawing.FontStyle.Regular);
this.ForeColor = System.Drawing.Color.Black;
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
this.Location = new System.Drawing.Point(0, 0);
this.MinimizeBox = true;
this.Name = "FrontDoorForm";
this.Text = "FrontDoorForm";
this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
this.Controls.SetChildIndex(this.buttonQuit, 0);
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.Button buttonQuit;
}
Just to close the question I will quote the answer from the comment:
Change the base form's WindowState back to Normal for a workaround. You can still get it Maximized in the derived form. Hans Passant
I cannot figure out how to get the MouseDown event when the mouse is down/clicked on the border of a Form. It is easy to see that it is raised when the mouse is down in the (I think its called) client area of the form, but it is never raised when it is down on the border.
Here is a SSCCE that demonstrates the issue. The label in the center of the form is only changed when the mouse is down on the client area and not the border.
Is there anyway to catch this event or have it be raised?
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace MouseEventTest
{
public partial class Form1 : Form
{
Random rand = new Random();
public Form1()
{
InitializeComponent();
}
private void Form1_MouseDown(object sender, MouseEventArgs e)
{
label1.Text = rand.Next().ToString();
}
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.label1 = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(42, 30);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(91, 13);
this.label1.TabIndex = 0;
this.label1.Text = "99999999999999";
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(185, 75);
this.Controls.Add(this.label1);
this.Name = "Form1";
this.Text = "Form1";
this.MouseDown += new System.Windows.Forms.MouseEventHandler(this.Form1_MouseDown);
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.Label label1;
}
}
EDIT: I have solved this problem, but it created another. If you are visting this question in the future here is a related question I asked. It (hopefully) will help me/us figure out when the mouse has been released too. WM_NCLBUTTONUP message not sent at the end of dragging a form, how to do so?
Override the WndProc method:
const int WM_NCLBUTTONDWN = 0xA1;
protected override void WndProc(ref Message m)
{
if (m.Msg == WM_NCLBUTTONDWN)
{
this.Text = "got it!";
}
base.WndProc(ref m);
}
Use this method and calculate for the border of your form. There's no way to handle it via "Form" because the border is not a part of the Form...
EDIT1:
As commented by Lars, there's no way to do this using WinForms. You will need to "go down" a floor and work with the WinForms infrastructure...