Click here to Skip to main content
15,910,411 members
Home / Discussions / C#
   

C#

 
GeneralRe: how to populate a single column from a table to a datagridview Pin
kssknov5-Dec-07 19:06
kssknov5-Dec-07 19:06 
AnswerRe: how to populate a single column from a table to a datagridview Pin
I.explore.code5-Dec-07 23:49
I.explore.code5-Dec-07 23:49 
GeneralPrint data from webbrowser used on windows form Pin
D i x y5-Dec-07 18:09
D i x y5-Dec-07 18:09 
GeneralJava script using windows form Pin
Satish - Developer5-Dec-07 17:53
Satish - Developer5-Dec-07 17:53 
GeneralRe: Java script using windows form Pin
Sathesh Sakthivel5-Dec-07 17:58
Sathesh Sakthivel5-Dec-07 17:58 
GeneralRe: Java script using windows form Pin
Satish - Developer5-Dec-07 18:09
Satish - Developer5-Dec-07 18:09 
GeneralRe: Java script using windows form Pin
Sun Rays5-Dec-07 18:36
Sun Rays5-Dec-07 18:36 
GeneralA tiny issue with ".NET Snap To Screen Form" Pin
EEssam5-Dec-07 17:48
EEssam5-Dec-07 17:48 
Hi,

The code here is working very good when the ForBorderStyle is NOT set to "None":

http://www.codeproject.com/KB/vb/SnapForm.aspx

In my application, it's set to None... And I move the form by holding down the right mouse button and moving it. The code still partially work, but when I approach the taskbar from the clock side it's not completely sticked to the corners.

I tried to figure out what wrong with code but no luck (and no experience).

The complete code is attached. Just create a new project and paste it.

Your help would be greatly appreciated.


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;

namespace WindowsFormsApplication11
{
public partial class Form1 : Form
{
public const int WM_NCLBUTTONDOWN = 0xA1;
public const int HT_CAPTION = 0x2;

[DllImportAttribute("user32.dll")]
public static extern int SendMessage(IntPtr hWnd,
int Msg, int wParam, int lParam);
[DllImportAttribute("user32.dll")]
public static extern bool ReleaseCapture();

public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{

}

# region SnapToDesktopBorder

private const int mSnapOffset = 35;
private const int WM_WINDOWPOSCHANGING = 70;

[StructLayout(LayoutKind.Sequential)]
public struct WINDOWPOS
{
public IntPtr hwnd;
public IntPtr hwndInsertAfter;
public int x;
public int y;
public int cx;
public int cy;
public int flags;
}

protected override void WndProc(ref Message m)
{
// Listen for operating system messages
switch (m.Msg)
{
case WM_WINDOWPOSCHANGING:
{
SnapToDesktopBorder(this, m.LParam, 0);
}
break;
}

base.WndProc(ref m);
}

public static void SnapToDesktopBorder(Form clientForm, IntPtr LParam, int widthAdjustment)
{
if (clientForm == null)
{
// Satisfies rule: Validate parameters
throw new ArgumentNullException("clientForm");
}

// Snap client to the top, left, bottom or right desktop border
// as the form is moved near that border.

try
{
// Marshal the LPARAM value which is a WINDOWPOS struct
WINDOWPOS NewPosition = new WINDOWPOS();
NewPosition = (WINDOWPOS)System.Runtime.InteropServices.Marshal.PtrToStructure(LParam, typeof(WINDOWPOS));

if (NewPosition.y == 0 || NewPosition.x == 0)
{
return;
// Nothing to do!
}

// Adjust the client size for borders and caption bar
Rectangle ClientRect = clientForm.RectangleToScreen(clientForm.ClientRectangle);
ClientRect.Width += SystemInformation.FrameBorderSize.Width - widthAdjustment;
ClientRect.Height += (SystemInformation.FrameBorderSize.Height + SystemInformation.CaptionHeight);

// Now get the screen working area (without taskbar)
Rectangle WorkingRect = Screen.GetWorkingArea(clientForm.ClientRectangle);

// Left border
if (NewPosition.x >= WorkingRect.X - mSnapOffset && NewPosition.x <= WorkingRect.X + mSnapOffset)
{
NewPosition.x = WorkingRect.X;
}

// Get screen bounds and taskbar height
// (when taskbar is horizontal)
Rectangle ScreenRect = Screen.GetBounds(Screen.PrimaryScreen.Bounds);
int TaskbarHeight = ScreenRect.Height - WorkingRect.Height;

// Top border (check if taskbar is on top
// or bottom via WorkingRect.Y)
if (NewPosition.y >= -mSnapOffset && (WorkingRect.Y > 0 && NewPosition.y <= (TaskbarHeight + mSnapOffset)) || (WorkingRect.Y <= 0 && NewPosition.y <= (mSnapOffset)))
{
if (TaskbarHeight > 0)
{
NewPosition.y = WorkingRect.Y;
// Horizontal Taskbar
}
else
{
NewPosition.y = 0;
// Vertical Taskbar
}
}

// Right border
if (NewPosition.x + ClientRect.Width <= WorkingRect.Right + mSnapOffset && NewPosition.x + ClientRect.Width >= WorkingRect.Right - mSnapOffset)
{
NewPosition.x = WorkingRect.Right - (ClientRect.Width + SystemInformation.FrameBorderSize.Width);
}

// Bottom border
if (NewPosition.y + ClientRect.Height <= WorkingRect.Bottom + mSnapOffset && NewPosition.y + ClientRect.Height >= WorkingRect.Bottom - mSnapOffset)
{
NewPosition.y = WorkingRect.Bottom - (ClientRect.Height + SystemInformation.FrameBorderSize.Height);
}

// Marshal it back
System.Runtime.InteropServices.Marshal.StructureToPtr(NewPosition, LParam, true);
}
catch (ArgumentException ex)
{
}
}


# endregion

private void Form1_MouseMove(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
ReleaseCapture();
SendMessage(Handle, WM_NCLBUTTONDOWN, HT_CAPTION, 0);
}
}
}
}
QuestionIs it possible to record the voice from phone using tapi with C#.Net ? Pin
Gopal.S5-Dec-07 17:28
Gopal.S5-Dec-07 17:28 
AnswerRe: Is it possible to record the voice from phone using tapi with C#.Net ? Pin
Sathesh Sakthivel5-Dec-07 17:34
Sathesh Sakthivel5-Dec-07 17:34 
GeneralRe: Is it possible to record the voice from phone using tapi with C#.Net ? Pin
Gopal.S5-Dec-07 18:34
Gopal.S5-Dec-07 18:34 
GeneralRe: Is it possible to record the voice from phone using tapi with C#.Net ? Pin
Sathesh Sakthivel5-Dec-07 19:03
Sathesh Sakthivel5-Dec-07 19:03 
GeneralDatagrid with multiple header............. Pin
P_Elza5-Dec-07 17:16
P_Elza5-Dec-07 17:16 
GeneralRe: Datagrid with multiple header............. Pin
Sathesh Sakthivel5-Dec-07 17:37
Sathesh Sakthivel5-Dec-07 17:37 
Generaledit position (cursor? carret?) of richtextbox Pin
sduhd5-Dec-07 16:05
sduhd5-Dec-07 16:05 
GeneralRe: edit position (cursor? carret?) of richtextbox Pin
Christian Graus5-Dec-07 16:12
protectorChristian Graus5-Dec-07 16:12 
GeneralSend Program Over eMail Pin
MasterSharp5-Dec-07 14:23
MasterSharp5-Dec-07 14:23 
GeneralRe: Send Program Over eMail Pin
Colin Angus Mackay5-Dec-07 14:26
Colin Angus Mackay5-Dec-07 14:26 
GeneralRe: Send Program Over eMail Pin
MasterSharp5-Dec-07 14:32
MasterSharp5-Dec-07 14:32 
GeneralRe: Send Program Over eMail Pin
Christian Graus5-Dec-07 16:13
protectorChristian Graus5-Dec-07 16:13 
GeneralRe: Send Program Over eMail Pin
MasterSharp6-Dec-07 10:39
MasterSharp6-Dec-07 10:39 
GeneralCatch Specific exception in SqlClient Pin
Skanless5-Dec-07 13:18
Skanless5-Dec-07 13:18 
GeneralRe: Catch Specific exception in SqlClient Pin
Colin Angus Mackay5-Dec-07 14:23
Colin Angus Mackay5-Dec-07 14:23 
GeneralRe: Catch Specific exception in SqlClient Pin
Skanless5-Dec-07 14:44
Skanless5-Dec-07 14:44 
GeneralRe: Catch Specific exception in SqlClient Pin
Ennis Ray Lynch, Jr.5-Dec-07 16:16
Ennis Ray Lynch, Jr.5-Dec-07 16:16 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.