|
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);
}
}
}
}
|
|
|
|
|
Hi,
Is it possible to record the voice from phone using tapi with C#.Net ?
Thanks,
Gopal.S
|
|
|
|
|
Yes.
SSK.
Anyone who says sunshine brings happiness has never danced in the rain.
|
|
|
|
|
Hi,
Thanks for your reply. Could you send any sample or material links for this one?
Regards,
Gopal.S
|
|
|
|
|
|
Hi friends...
is it possible to have a datagrid with multiple header?
i want to generate a report in datagrid.
the form should be like this
Heading 1 | Heading 2| Heading 3 | Main Heading
-----------|-----------|-----------|
Sh1 | Sh2 | Sh1 | Sh2 |SH1 | Sh 2 |Sub Heading
----|------|-----|-----|----|------|
|Rows......
-----------------------------------|
how is it done?
somebody plz help me....
|
|
|
|
|
|
I want to store the edit position of a richtextbox and set the position back after I renewed it's contents.
Thanks.
|
|
|
|
|
I believe the SelectionStart property stores where the caret is, if there's no selection.
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
OK; I tried ClickOnce, and that didn't work. How would I send a program with some DirectX and audio files in an eMail? Thanks.
- I love D-flat!
|
|
|
|
|
* In a zip file
* In a self extracting zip file
* As an MSI file
* as a link to a download
A lot of corporate mail systems will block attachments that it sees as dangerous. So EXEs and MSI files prossibly won't get through. ZIP files are also often searched by email scanners so if those files are found in there also it will get blocked.
|
|
|
|
|
Well, I see, but every time I send, it always says I'm missing files (or, the other person sees that...). So is there anything I need to include?
- I love D-flat!
|
|
|
|
|
Well, your first step would be to make sure the person on the other end has DirectX and .NET installed. Then zip up the files from the directory where you run them ( so they are in the right folders ), rename the zip to zip1 or something if need be ( to avoid it being rejected ) and send
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Is there anyway to add that to the packge, because I'm pretty sure they don't have anything that I do with resources.
*Also, to let people know, I hope to find a true programming class within a year or two, so I can finally get REALLY going.
- I love D-flat!
|
|
|
|
|
I am writing an HR application to add new employees. Currently, I am having an issue where I want to send a specific message base on the exception that is received. In my database SNN is a unique key hence if an SSN is being added that already exist in the DB a Unique key violation exception is thrown. If the UserID already exist a Primary Key violation exception is thrown. I am certain this is possible but just not sure what is best practice. I can write a method which search the DB first and if the record is found thrown an error message based on whether it was the Unique key violation or the PK violation. I have also been searching MSDN to see if I can identify the C# SqlClient error ID for either scenarios and based on the exception ID, alert the user with the right error message.
Any advice will be greatly appreciated.
Skan
If you knew it would not compile why didn't you tell me?!?!?!
|
|
|
|
|
Skanless wrote: I have also been searching MSDN to see if I can identify the C# SqlClient error ID for either scenarios and based on the exception ID, alert the user with the right error message
All the Ids can be found in SQL Server itself.
SELECT * FROM sys.messages or
SELECT * FROM sysmessages (if you are on SQL Server 2000)
|
|
|
|
|
Thanks dude, I found them. I would still like to know what best practice for a situation like this.
Skan
If you knew it would not compile why didn't you tell me?!?!?!
|
|
|
|
|
Use IF Exists in a trigger and then throw custom exceptions from the sp. However, SQL server will natively through the message number so there is no reason for custom handling to catch it.
Need a C# Consultant? I'm available.
Happiness in intelligent people is the rarest thing I know. -- Ernest Hemingway
|
|
|
|
|
This worked perfectly!!!
IF EXISTS
(SELECT Emp_Login_ID FROM Employees where Emp_Login_ID = @Emp_Login_ID )
RETURN -1
ELSE
IF EXISTS
(SELECT Emp_SSN FROM Employees where Emp_SSN = @Emp_SSN )
RETURN -2
ELSE
INSERT INTO........
I am no longer receiving the Exception. However, I am not sure how to throw the Error message in C#. How would C# know to throw and Exception if the insert does nto execute? Thanks for you help.
Note: All this is done in a single stored procedure. Which is then called in the application in a try, catch statement.
Skan
If you knew it would not compile why didn't you tell me?!?!?!
modified on Thursday, December 06, 2007 12:44:52 AM
|
|
|
|
|
Thanks for the help guys. I got it working with the following lines of code. I will simplify my code later but just need to get it working.
SqlParameter paramReturnValue = new SqlParameter();
paramReturnValue.ParameterName = "@return_value";
paramReturnValue.SqlDbType = SqlDbType.Int;
paramReturnValue.Direction = ParameterDirection.ReturnValue;
cmd.Parameters.Add(paramReturnValue);
Skan
If you knew it would not compile why didn't you tell me?!?!?!
|
|
|
|
|
A System.Data.SqlClient.SqlException has an Errors array which contains the specific error(s).
I search it for 2601 (unique index violation) or 2627 (primary key violation), and if present I wrap it in a custom exception.
You can take a look at my DatabaseAccessor article which contains an enum of the code I support.
|
|
|
|
|
Hello everybody scenario is as follows:
Application multithreaded in windowsForms
C# Language
Framework 2.0 in VisualStudio 2005
This application works with several business logic processes asynchronous manner.
Play audio and video with DirectX
Handles timers who control the times of execution.
Everything works correctly while not use objects pictureBox with animated images (GIF). When I need to load an Animated Gif in a pictureBox and view the animation at run time, the processor is fired at a 100%, that happens only with a lively Gif image. Using a JPG or PNG static images, the performance is not affected. But implementation requires at least play 10 Gif animated, distributed in the Form.
When you try to load all these images, many are not displayed in the pictureBox and those displayed lose animation or reproduce them too slowly and with a delay that makes Losing the aesthetics chart.
To accomplish this I found some documentation msdn Class ImageAnimator, which to deploy in a component created for myself, I get the same problem of performance that picture box.
If anyone has an idea of what's going on and how to solve am waiting for their early comments.
Thankyou.
|
|
|
|
|
I'd avoid the picture box and draw the images yourself. The picture box doesn't handle animated gifs, so you must have your own code in there somewhere already, right ?
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
i am trying to export a excel file to the user when they click a button, i tried Response.WriteFile("filename"), it only display the content in the same page, can someone tell me whats the code to prompt them with a save as option? Thank you in advance.
|
|
|
|
|
I think I just answered this in the VB forum. The ASP.NET forum is the only forum that is right for this question, please don't crosspost
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|