Recently I made (mostly out of curiosity) a borderless form. After making my own title bar which includes the title, and the three buttons(minimize, maximize and close), just like every normal Windows program. I also made the code for these buttons (just ask if you want to see the code).
However, I've noticed that there are no animations. What I mean is that, e.g. if I click the minimize button, there is no animation, the program instantly disappears (it doesn't close, the button works, but without an animation). This happens in all cases: When I open the program it instantly appears, when I close it, it instantly disappears.
Is there some sort of way to use these animations that standard Windows programs use?
It doesn't seem possible to have the animation effect on a borderless form. However, there are two possible workarounds.
Set the FormBorderStyle back to Sizable just before a Minimize or Restore, and then back to none aftewards.
Use the AnimateWindow function instead. The animations tend to happen where the window is currently located. The functions can be applied to any Control, not just top level windows.
Here is some sample code:
class FormA : Form {
private const int WM_SYSCOMMAND = 0x0112;
private const int SC_MINIMIZE = 0xF020;
private const int SC_RESTORE = 0xF120;
protected override void WndProc(ref Message m) {
switch (m.Msg) {
case WM_SYSCOMMAND:
int command = m.WParam.ToInt32();
if (command == SC_RESTORE) {
this.FormBorderStyle = FormBorderStyle.Sizable;
this.ControlBox = true;
}
break;
}
base.WndProc(ref m);
}
}
[DllImport("user32.dll")]
static extern bool AnimateWindow(IntPtr hwnd, int dwTime, int dwFlags);
private const int AW_VER_POSITIVE = 0x00000004;
private const int AW_VER_NEGATIVE = 0x00000008;
private const int AW_SLIDE = 0x00040000;
private const int AW_HIDE = 0x00010000;
[STAThread]
static void Main() {
Application.EnableVisualStyles();
Form f = new FormA();
f.ControlBox = false;
f.FormBorderStyle = FormBorderStyle.None;
bool isMinimizing = false;
var mb = new Button { Text = "Min" };
mb.Click += delegate {
isMinimizing = true;
f.FormBorderStyle = FormBorderStyle.Sizable;
f.ControlBox = true;
f.WindowState = FormWindowState.Minimized;
f.FormBorderStyle = FormBorderStyle.None;
isMinimizing = false;
//AnimateWindow(f.Handle, 300, AW_SLIDE | AW_VER_POSITIVE | AW_HIDE);
};
f.SizeChanged += delegate {
if (isMinimizing)
return;
if (f.WindowState != FormWindowState.Minimized)
f.FormBorderStyle = FormBorderStyle.None;
};
f.Controls.Add(mb);
Application.Run(f);
}
I know that this question has been asked over a year ago, but i had the same problem and found a very nice solution.
Look at this repo at Github.
Add FormBase.cs and Native.cs to your project.
What you have to do is basically to create a Form, f.e. Main.cs and derive it from FormBase
Main.cs
public Main()
{
InitializeComponent();
// Redraw gripper on resize
this.SetStyle(ControlStyles.ResizeRedraw, true);
// Ability to minimize/restore the form with animation
this.FormBorderStyle = FormBorderStyle.Sizable;
}
// Draw the gripper on the bottom right corner
protected override void OnPaint(PaintEventArgs e)
{
Rectangle rc = new Rectangle(this.ClientSize.Width - cGrip, this.ClientSize.Height - cGrip, cGrip, cGrip);
ControlPaint.DrawSizeGrip(e.Graphics, this.BackColor, rc);
rc = new Rectangle(0, 0, this.ClientSize.Width, cCaption);
e.Graphics.FillRectangle(Brushes.DarkBlue, rc);
SizeGripStyle = SizeGripStyle.Hide;
}
// Override WndProc to add resize ability -> Cursor
protected override void WndProc(ref Message m)
{
if (m.Msg == 0x84)
{ // Trap WM_NCHITTEST
Point pos = new Point(m.LParam.ToInt32() & 0xffff, m.LParam.ToInt32() >> 16);
pos = this.PointToClient(pos);
if (pos.X >= this.ClientSize.Width - cGrip && pos.Y >= this.ClientSize.Height - cGrip)
{
m.Result = (IntPtr)17; // HTBOTTOMRIGHT
return;
}
}
base.WndProc(ref m);
}
I also removed line 147 in FormBase.cs, because my Form had rounded edges
//SetWindowRegion(m.HWnd, 0, 0, pos.cx, pos.cy);
Related
Recently I made (mostly out of curiosity) a borderless form. After making my own title bar which includes the title, and the three buttons(minimize, maximize and close), just like every normal Windows program. I also made the code for these buttons (just ask if you want to see the code).
However, I've noticed that there are no animations. What I mean is that, e.g. if I click the minimize button, there is no animation, the program instantly disappears (it doesn't close, the button works, but without an animation). This happens in all cases: When I open the program it instantly appears, when I close it, it instantly disappears.
Is there some sort of way to use these animations that standard Windows programs use?
It doesn't seem possible to have the animation effect on a borderless form. However, there are two possible workarounds.
Set the FormBorderStyle back to Sizable just before a Minimize or Restore, and then back to none aftewards.
Use the AnimateWindow function instead. The animations tend to happen where the window is currently located. The functions can be applied to any Control, not just top level windows.
Here is some sample code:
class FormA : Form {
private const int WM_SYSCOMMAND = 0x0112;
private const int SC_MINIMIZE = 0xF020;
private const int SC_RESTORE = 0xF120;
protected override void WndProc(ref Message m) {
switch (m.Msg) {
case WM_SYSCOMMAND:
int command = m.WParam.ToInt32();
if (command == SC_RESTORE) {
this.FormBorderStyle = FormBorderStyle.Sizable;
this.ControlBox = true;
}
break;
}
base.WndProc(ref m);
}
}
[DllImport("user32.dll")]
static extern bool AnimateWindow(IntPtr hwnd, int dwTime, int dwFlags);
private const int AW_VER_POSITIVE = 0x00000004;
private const int AW_VER_NEGATIVE = 0x00000008;
private const int AW_SLIDE = 0x00040000;
private const int AW_HIDE = 0x00010000;
[STAThread]
static void Main() {
Application.EnableVisualStyles();
Form f = new FormA();
f.ControlBox = false;
f.FormBorderStyle = FormBorderStyle.None;
bool isMinimizing = false;
var mb = new Button { Text = "Min" };
mb.Click += delegate {
isMinimizing = true;
f.FormBorderStyle = FormBorderStyle.Sizable;
f.ControlBox = true;
f.WindowState = FormWindowState.Minimized;
f.FormBorderStyle = FormBorderStyle.None;
isMinimizing = false;
//AnimateWindow(f.Handle, 300, AW_SLIDE | AW_VER_POSITIVE | AW_HIDE);
};
f.SizeChanged += delegate {
if (isMinimizing)
return;
if (f.WindowState != FormWindowState.Minimized)
f.FormBorderStyle = FormBorderStyle.None;
};
f.Controls.Add(mb);
Application.Run(f);
}
I know that this question has been asked over a year ago, but i had the same problem and found a very nice solution.
Look at this repo at Github.
Add FormBase.cs and Native.cs to your project.
What you have to do is basically to create a Form, f.e. Main.cs and derive it from FormBase
Main.cs
public Main()
{
InitializeComponent();
// Redraw gripper on resize
this.SetStyle(ControlStyles.ResizeRedraw, true);
// Ability to minimize/restore the form with animation
this.FormBorderStyle = FormBorderStyle.Sizable;
}
// Draw the gripper on the bottom right corner
protected override void OnPaint(PaintEventArgs e)
{
Rectangle rc = new Rectangle(this.ClientSize.Width - cGrip, this.ClientSize.Height - cGrip, cGrip, cGrip);
ControlPaint.DrawSizeGrip(e.Graphics, this.BackColor, rc);
rc = new Rectangle(0, 0, this.ClientSize.Width, cCaption);
e.Graphics.FillRectangle(Brushes.DarkBlue, rc);
SizeGripStyle = SizeGripStyle.Hide;
}
// Override WndProc to add resize ability -> Cursor
protected override void WndProc(ref Message m)
{
if (m.Msg == 0x84)
{ // Trap WM_NCHITTEST
Point pos = new Point(m.LParam.ToInt32() & 0xffff, m.LParam.ToInt32() >> 16);
pos = this.PointToClient(pos);
if (pos.X >= this.ClientSize.Width - cGrip && pos.Y >= this.ClientSize.Height - cGrip)
{
m.Result = (IntPtr)17; // HTBOTTOMRIGHT
return;
}
}
base.WndProc(ref m);
}
I also removed line 147 in FormBase.cs, because my Form had rounded edges
//SetWindowRegion(m.HWnd, 0, 0, pos.cx, pos.cy);
I want this:
Pretty much, my form is resizeable if BorderStyle is set to None and isMDIContainer = false;
But, how do I get my form resizeable if BordeStyle is set to None and isMDICOntainer = true?
https://gyazo.com/6fe87f127a3b2768c152e64d372593c1
This is an example. You can see the form is resizeable just fine. But as soon as the MDI comes in play, it doesn't work anymore.
Here is the current code:
private const int cCaption = 62;
private const int cGrip = 16;
protected override void OnPaint(PaintEventArgs e)
{
Rectangle rc = new Rectangle(this.ClientSize.Width - cGrip, this.ClientSize.Height - cGrip, cGrip, cGrip);
ControlPaint.DrawSizeGrip(e.Graphics, this.BackColor, rc);
rc = new Rectangle(0, 0, this.ClientSize.Width, cCaption);
// e.Graphics.FillRectangle(Brushes.Blue, rc);
}
protected override void WndProc(ref Message m)
{
if (m.Msg == 0x84)
{ // Trap WM_NCHITTEST
Point pos = new Point(m.LParam.ToInt32());
pos = this.PointToClient(pos);
if (pos.Y < cCaption)
{
m.Result = (IntPtr)2; // HTCAPTION
return;
}
if (pos.X >= this.ClientSize.Width - cGrip && pos.Y >= this.ClientSize.Height - cGrip)
{
m.Result = (IntPtr)17; // HTBOTTOMRIGHT
return;
}
}
base.WndProc(ref m);
}
The explanation from Jimi was right. The OnPaint event only draws your Rectangle on the MainForm, while what you see is the MdiClient control. This control covers the background of the MainForm (like you set a panel control and set Dock = fill), so you cannot see and click the rectangle at bottom right to resize.
One way for you to be able to see and click on the rectangle for resizing is set the padding for MainForm, like this:
protected override void OnClientSizeChanged(EventArgs e)
{
if (this.WindowState != lastState || lastState == FormWindowState.Normal)
{
lastState = this.WindowState;
OnWindowStateChange(e);
}
base.OnClientSizeChanged(e);
}
private void OnWindowStateChange(EventArgs e)
{
if (WindowState == FormWindowState.Maximized)
{
Padding = new Padding(0);
}
else
{
Padding = new Padding(7);
}
}
So at normal window state (not fullscreen), the MdiClient will not cover all surface of mainform.
I find the color of this is not good. So you may want to change the background of the main form that fit the background of MdiClient, or use this approach to draw rectangles around your form for resizing like normal.
How to resize borderless form from all edges
I am trying to paint the split line that appears when you drag a splitter control:
As you can see from this image, the default splitter is a checkerboard.
...this doesn't work:
public partial class MockForm : Form
{
public MockForm()
{
InitializeComponent();
this.splitter1.Paint += splitter1_Paint;
}
private void splitter1_Paint(object sender, PaintEventArgs e)
{
e.Graphics.Clear(Color.Red);
}
}
this just paints the background of the control but not the splitter when it's dragged.
Any ideas?
The answer posted by LarsTech is really good, But the handler flickers are somehow annoying. Instead of showing the control in Form, if you show a Form as splitter handler and show it above the Container of splitter, the flickers will be gone.
HighLight f = new HighLight() { BackColor = Color.Red };
private void splitter1_SplitterMoving(object sender, SplitterEventArgs e)
{
this.splitter1.Parent.Refresh();
f.Location = this.splitter1.Parent.PointToScreen(new Point(e.SplitX, e.SplitY));
f.Size = this.splitter1.Size;
if (!f.Visible)
f.ShowInactiveTopmost();
}
private void splitter1_SplitterMoved(object sender, SplitterEventArgs e)
{
f.Hide();
}
Here is the form which I used as highlight:
using System;
using System.Runtime.InteropServices;
using System.Windows.Forms;
public class HighLight : Form
{
public HighLight()
{
Opacity = 0;
FormBorderStyle = FormBorderStyle.None;
ShowInTaskbar = false;
StartPosition = FormStartPosition.Manual;
}
protected override void OnDeactivate(EventArgs e)
{
base.OnDeactivate(e);
this.Hide();
}
private const int SW_SHOWNOACTIVATE = 4;
private const int HWND_TOPMOST = -1;
private const uint SWP_NOACTIVATE = 0x0010;
[DllImport("user32.dll", EntryPoint = "SetWindowPos")]
static extern bool SetWindowPos(int hWnd, int hWndInsertAfter,
int X, int Y, int cx, int cy, uint uFlags);
[DllImport("user32.dll")]
static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
public void ShowInactiveTopmost()
{
ShowWindow(this.Handle, SW_SHOWNOACTIVATE);
SetWindowPos(this.Handle.ToInt32(), HWND_TOPMOST,
this.Left, this.Top, this.Width, this.Height,
SWP_NOACTIVATE);
this.Opacity = 1;
}
}
To see a custom splitter which supports transparent handler take a look at this related post. In the other post I created a new splitter control using source codes of original splitter, but changed rendering the highlight:
Change Splitter Highlighting/Resize Line
The old Splitter control uses a private painting method to produce that checkerboard effect, so there isn't any thing you can override to replace that.
You can fake it by dragging your own control in the space of the checkerboard control you see on the screen. This may produce some flicker:
Control draggingControl = new Control { BackColor = Color.Green, Visible = false };
public MockForm() {
InitializeComponent();
this.Controls.Add(draggingControl);
splitter1.SplitterMoving += splitter1_SplitterMoving;
splitter1.SplitterMoved += splitter1_SplitterMoved;
}
void splitter1_SplitterMoving(object sender, SplitterEventArgs e) {
draggingControl.Bounds = new Rectangle(new Point(e.X - (e.X - e.SplitX), 0),
splitter1.Size);
if (!draggingControl.Visible) {
draggingControl.Visible = true;
draggingControl.BringToFront();
}
this.Refresh();
}
void splitter1_SplitterMoved(object sender, SplitterEventArgs e) {
draggingControl.Visible = false;
this.Refresh();
}
The Splitter control was deprecated in favor of the SplitContainer control.
I am trying to do something like Kinect adventures with Kinect SDK i.e. when the mouse stays in a certain area for a specific period of time, the native click event is to be fired.
The problem is that I do not get the expected results, since I get random clicking most times. I tried to check with breakpoints etc.
Most often, when my hand is not visible, the cursor goes to the corner of the screen and starts clicking. This is most probably because Math.Abs(lastX - cursorX) < threshold sets to true.
I have tried changing the threshold values to 200, but it fires a click st the start, and afterwards I am not get expected left clicks, when I hold the cursor in a certain position for some time. Any suggestions would be greatly appreciated. Here's the code:
//SkeletonFrameReadyevent
foreach (SkeletonData sd in e.SkeletonFrame.Skeletons)
{
if (sd.TrackingState == SkeletonTrackingState.Tracked)
{
// make sure both hands are tracked
if (sd.Joints[JointID.HandLeft].TrackingState == JointTrackingState.Tracked &&
sd.Joints[JointID.HandRight].TrackingState == JointTrackingState.Tracked)
{
int cursorX, cursorY;
// get the left and right hand Joints
Joint jointRight = sd.Joints[JointID.HandRight];
Joint jointLeft = sd.Joints[JointID.HandLeft];
// scale those Joints to the primary screen width and height
Joint scaledRight = jointRight.ScaleTo((int)SystemParameters.PrimaryScreenWidth, (int)SystemParameters.PrimaryScreenHeight, SkeletonMaxX, SkeletonMaxY);
Joint scaledLeft = jointLeft.ScaleTo((int)SystemParameters.PrimaryScreenWidth, (int)SystemParameters.PrimaryScreenHeight, SkeletonMaxX, SkeletonMaxY);
// figure out the cursor position based on left/right handedness
cursorX = (int)scaledRight.Position.X;
cursorY = (int)scaledRight.Position.Y;
//default false, for mouse move, set to true for mouse click
bool leftClick;
if (lastY == 0)
{
lastX = cursorX;
lastY = cursorY;
}
leftClick = false;
if (Math.Abs(lastX - cursorX) < threshold && Math.Abs(lastY - cursorY) < threshold)
{
if (Math.Abs(lastClick.Subtract(DateTime.Now).TotalSeconds) > 1)
{
//Mouse click here
leftClick = true;
}
}
//Mouse click when leftDown is true, else Mousemove
NativeMethods.SendMouseInput(cursorX, cursorY, (int)SystemParameters.PrimaryScreenWidth, (int)SystemParameters.PrimaryScreenHeight, leftClick);
return;
}
}
}
NativeMthods.cs class has this function:
public static void SendMouseInput(int positionX, int positionY, int maxX, int maxY, bool leftDown)
{
if(positionX > int.MaxValue)
throw new ArgumentOutOfRangeException("positionX");
if(positionY > int.MaxValue)
throw new ArgumentOutOfRangeException("positionY");
Input[] i = new Input[2];
// move the mouse to the position specified
i[0] = new Input();
i[0].Type = InputMouse;
i[0].MouseInput.X = (positionX * 65535) / maxX;
i[0].MouseInput.Y = (positionY * 65535) / maxY;
i[0].MouseInput.Flags = MouseEventAbsolute | MouseEventMove;
// determine if we need to send a mouse down or mouse up event
if(leftDown)
{
i[1] = new Input();
i[1].Type = InputMouse;
i[1].MouseInput.Flags = MouseEventLeftDown;
i[1].MouseInput.Flags |= MouseEventLeftUp;
}
// send it off
uint result = SendInput(2, i, Marshal.SizeOf(i[0]));
if(result == 0)
throw new Win32Exception(Marshal.GetLastWin32Error());
}
Try something like this:
public class myMouseClass: IMessageFilter //Must implement IMessageFilter
{
[DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
public static extern void mouse_event(long dwFlags, long dx, long dy, long cButtons, long dwExtraInfo);
//Constants
private const int MOUSEEVENTF_LEFTDOWN = 0x02;
private const int MOUSEEVENTF_LEFTUP = 0x04;
private const int MOUSEEVENTF_RIGHTDOWN = 0x08;
private const int MOUSEEVENTF_RIGHTUP = 0x10;
private const int WM_MOUSEMOVE = 0x0200;
private int Threshold = 20; //how far the mouse should move to reset timer
private int StartLocationX = 0; //stores starting X value
private int StartLocationY = 0; //stores starting Y value
private Timer timerHold = new Timer(); //timer to trigger mouse click
//Start Mouse monitoring by calling this. This will also set the timer.
private void StartFilterMouseEvents()
{
timerHold.Interval = 1000; //how long mouse must be in threshold.
timerHold.Tick = new EventHandler(timerHold_Tick);
Application.AddMessageFilter((IMessageFilter) this);
}
//Stop Mouse monitoring by calling this and unset the timer.
private void StopFilterMouseEvents()
{
timerHold.Stop();
timerHold -= timerHold_Tick;
Application.RemoveMessageFilter((IMessageFilter) this);
}
//This will start when Application.AddMessageFilter() is called
public bool PreFilterMessage(ref Message m)
{
if (m.Msg == WM_MOUSEMOVE)
{
if((Cursor.Position.X > StartLocationX + 20)||(Cursor.Position.X > StartLocationX - 20))&&
((Cursor.Position.Y > StartLocationY + 20)||(Cursor.Position.Y > StartLocationY - 20))
{
timerHold.Stop(); //stops timer if running
timerHold.Start(); //starts it again with new position.
StartLocationX = Cursor.Position.X;
StartLocationY = Cursor.Position.Y;
}
}
return false;
}
//This event gets fired when the timer has not been reset for 1000ms
public void timerHold_Tick(object sender, EventArgs e)
{
mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
}
}
How would i go about stopping a form from being moved. I have the form border style set as FixedSingle and would like to keep it this way because it looks good in vista :)
Take a look at this link. You might be interested in option #3. It will require you to wrap some native code, but should work. There's also a comment at the bottom of the link that shows an easier way to do it. Taken from the comment (can't take credit for it, but I'll save you some searching):
protected override void WndProc(ref Message message)
{
const int WM_SYSCOMMAND = 0x0112;
const int SC_MOVE = 0xF010;
switch(message.Msg)
{
case WM_SYSCOMMAND:
int command = message.WParam.ToInt32() & 0xfff0;
if (command == SC_MOVE)
return;
break;
}
base.WndProc(ref message);
}
You can set the FormBorderStyle property of the Form to None
this.FormBorderStyle=System.Windows.Forms.FormBorderStyle.None
I found this to stop the form from moving (its in c#)
protected override void WndProc(ref Message m)
{
const int WM_SYSCOMMAND = 0x0112;
const int SC_MOVE = 0xF010;
switch (m.Msg)
{
case WM_SYSCOMMAND:
int command = m.WParam.ToInt32() & 0xfff0;
if (command == SC_MOVE)
return;
break;
}
base.WndProc(ref m);
}
Found here
Try to override WndProc:
protected override void WndProc(ref Message m)
{
const int WM_NCLBUTTONDOWN = 161;
const int WM_SYSCOMMAND = 274;
const int HTCAPTION = 2;
const int SC_MOVE = 61456;
if ((m.Msg == WM_SYSCOMMAND) && (m.WParam.ToInt32() == SC_MOVE))
{
return;
}
if ((m.Msg == WM_NCLBUTTONDOWN) && (m.WParam.ToInt32() == HTCAPTION))
{
return;
}
base.WndProc(ref m);
}
It's not all pretty (there is some flashing going on when you try to move the form), but you can use the LocationChanged property to keep the form where you want it:
private Point _desiredLocation;
// assign the _desiredLocation variable with the form location at some
// point in the code where you know that the form is in the "correct" position
private void Form_LocationChanged(object sender, EventArgs e)
{
if (this.Location != _desiredLocation)
{
this.Location = _desiredLocation;
}
}
Out of curiousity; why would you want to do this?
In Windows, the WS_CAPTION style is the non-client area that allows your window to be moved with a mouse. So the easiest way to do what you want is to remove this style from your window.
However, if you need to have a caption and still achieve what you want, then the next style would be to capture the WM_NCHITTEST message and check for HTCAPTION. If the code is HTCAPTION, return NTNOWHERE instead. This will prevent the default window procedure from executing the default move window thing.
It's not a good practice to make your form immovable. I'd think agfain about it if I were you.
Anyway, you can do this by overridding the WinProc to disable the [Move] menuitem from the system menu.
[DllImport("user32.dll")]
private static extern Int32 EnableMenuItem ( System.IntPtr hMenu , Int32uIDEnableItem, Int32 uEnable);
private const Int32 HTCAPTION = 0×00000002;
private const Int32 MF_BYCOMMAND =0×00000000;
private const Int32 MF_ENABLED =0×00000000;
private const Int32 MF_GRAYED =0×00000001;
private const Int32 MF_DISABLED =0×00000002;
private const Int32 SC_MOVE = 0xF010;
private const Int32 WM_NCLBUTTONDOWN = 0xA1;
private const Int32 WM_SYSCOMMAND = 0×112;
private const Int32 WM_INITMENUPOPUP = 0×117;
protected override void WndProc(ref System.Windows.Forms.Message m )
{
if (m.Msg == WM_INITMENUPOPUP)
{
//handles popup of system menu
if ((m.LParam.ToInt32() / 65536) != 0) // 'divide by 65536 to get hiword
{
Int32 AbleFlags = MF_ENABLED;
if (!Moveable)
{
AbleFlags = MF_DISABLED | MF_GRAYED; // disable the move
}
EnableMenuItem(m.WParam, SC_MOVE, MF_BYCOMMAND | AbleFlags);
}
}
if (!Moveable)
{
if (m.Msg == WM_NCLBUTTONDOWN) //cancels the drag this is IMP
{
if (m.WParam.ToInt32() == HTCAPTION) return;
}
if (m.Msg == WM_SYSCOMMAND) // Cancels any clicks on move menu
{
if ((m.WParam.ToInt32() & 0xFFF0) == SC_MOVE) return;
}
}
base.WndProc(ref m);
}
Also, you can handle OnMove event of your form. But I think this will cause some flickering:
private void Form1_Move(object sender, EventArgs e)
{
this.Location = defaultLocation;
}
Just change the FormBorderStyle property to None.
change the Form property StartPostion to Manual.
Then, handle the LocationChanged event:
private void frmMain_LocationChanged(object sender, EventArgs e)
{
Location = new Point(0, 0);
}
Go to form events-> Location changed
write the following code
Location = new Point(this.Width,this.Height);
I would question your need to make the form unmovable. This doesn't sound nice. You could of course save the location of the window when the window closes and reopen the window into that position. That gives the user some control over where the window should be located.
You can subscribe to the Form.Move event and reposition from it.
Just reset the location on formlocation_changed event to where it was i.e. set the Form.Location to a variable before it's moved and when the user tries to move it, it will go back to the variable location you set it to.
Private Sub MyFormLock()
Me.Location = New Point(0, 0)
End Sub
Private Sub SearchSDR_LocationChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.LocationChanged
Call MyFormLock()
End Sub
You can try:
this.Locked = true;