|
Hi Amar Chaudhary.
You can do it, using InteropServices.
Example:
First you need attach the follow namespace
using System.Runtime.InteropServices;
Second you need import the Microsoft Windows Runtime dll's for declare the extern methods.
[DllImportAttribute("user32.dll")]<br />
public static extern bool ReleaseCapture();<br />
<br />
[DllImportAttribute("user32.dll")]<br />
public static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam);
Third you need declare the follow constants and methods for invoke the functions
private const int WM_NCLBUTTONDOWN = 0xA1;<br />
private const int HTCAPTION = 0x2;<br />
<br />
private void MoveForm()<br />
{<br />
ReleaseCapture();<br />
SendMessage(this.Handle, WM_NCLBUTTONDOWN, HTCAPTION, 0);<br />
}<br />
<br />
protected override void WndProc(ref Message m)<br />
{<br />
base.WndProc(ref m);<br />
<br />
int WM_NCHITTEST = 0x84;<br />
if (m.Msg == WM_NCHITTEST)<br />
{<br />
int HTCLIENT = 1;<br />
int HTCAPTION = 2;<br />
if (m.Result.ToInt32() == HTCLIENT)<br />
{<br />
m.Result = (IntPtr)HTCAPTION;<br />
}<br />
}<br />
}
Finally you need call the function with any MouseDown event
private void button1_MouseDown(object sender, MouseEventArgs e)<br />
{<br />
if (e.Button == MouseButtons.Left)<br />
{<br />
this.MoveForm();<br />
}<br />
}
Remember that you can replace the "this.Handle" for you Window Handle that you want move.
I hope that this resolve your problem.
SINCERELY.
ANTHONY ACUÑA
PREFERED PHRASE:
SOMEBODY TELL ME WHY IS MORE REAL WHEN I DREAM THAT I AM WAKE?
|
|
|
|
|
That's great. Thanks for the info.
|
|
|
|
|
you got my 5
It is Good to be Important but!
it is more Important to be Good
[My Question]
|
|
|
|
|
hey shopi30,
I tried using the code, but could not get it working. I can move "my" form by using this.Handle, but if I target another handle, like iexplore, I get nothing. I have tried getting the process handle by process.Handle, and also process.MainHandle, but no luck. Do I have to set focus to the process that I want to move? If so, how do I do that? Also, is there any way that I can specify the x and y co-ordinates of the window, or is it all based on the cursor?
|
|
|
|
|
Hi Now_Loading.
Try using:
[DllImportAttribute("user32.dll")]<br />
private extern static IntPtr GetForegroundWindow();
And change "this.Handle" to "GetForegroundWindow()"
GetForegroundWindow method return the Handle from the current window active.
If this don't solve your problem tell me and I'll be sending you other options.
By the way if you can help me with these System.Data.OleDb & Microsoft Excel I'll be thankful with you.
SINCERELY.
ANTHONY ACUÑA
PREFERED PHRASE:
SOMEBODY TELL ME WHY IS MORE REAL WHEN I DREAM THAT I AM WAKE?
|
|
|
|
|
I have one form.
On the form I have many different controls: panels, buttons, datagridviews and others...
How can I do to do when I Click on controls, I have a Message with Control Name?
|
|
|
|
|
In your click-Handler there's a parameter called sender . You can cast it and the get the name of the control.
Like that:
private void button1_Click(object sender, EventArgs e)
{
MessageBox.Show(((Button)sender).Name);
}
Make sure to do a proper cast if you use a general click handler for all controls.
E.g.
if(sender is Button) { (Button)... }
if(sender is Label) { (Label)... }
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
No, I don't want make click handler for all Controls,
I want use for this for example IMessageFilter
public DataForm()
{
InitializeComponent();
MyMessageFilter MessageFilter = new MyMessageFilter();
Application.AddMessageFilter(MessageFilter);
}
class MyMessageFilter : IMessageFilter
{
const int WM_LBUTTONCLICK = 0x0201;
public bool PreFilterMessage(ref Message m)
{
if (m.Msg == WM_LBUTTONCLICK)
{
???
???
???
}
return false;
}
}
|
|
|
|
|
I haven't used a MessageFilter yet, but the Message struct contains a property named hwnd . You can use Control.FromHandle(m.hwnd) to get the control associated with this message.
modified 12-Sep-18 21:01pm.
|
|
|
|
|
I have not understood, you could not give an example?
|
|
|
|
|
Not tested, but something like this:
Control c = Control.FromHandle(m.HWnd);
if(c != null)
{
string name;
if(c is Button) { name = ((Button)c).Name; }
else if(c is Label) { name = ((Label)c).Name; }
...
}
modified 12-Sep-18 21:01pm.
|
|
|
|
|
In what event I do use this:
Control c = Control.FromHandle(m.HWnd);
if(c != null)
{
...
}
|
|
|
|
|
You really need to improve your programming skills, the questions you ask are very basic.
You need to put it there where you placed the question marks:
f (m.Msg == WM_LBUTTONCLICK)
{
???
???
???
}
modified 12-Sep-18 21:01pm.
|
|
|
|
|
I want to display XML file in tree view and then by using popup menu by right clicking on nodes i want to add or delete entries in tree view to make changes in the xml file.
Please guide me about "popup menu", "Adding Nodes" and "Adding ImageList with different node entries".
Also please refer to any existing project if any.
|
|
|
|
|
Hi h@s@n.
You can create a ContextMenuStrip and call the method "show" when the MouseClick event has been fired on any node.
SINCERELY.
ANTHONY ACUÑA
PREFERED PHRASE:
SOMEBODY TELL ME WHY IS MORE REAL WHEN I DREAM THAT I AM WAKE?
|
|
|
|
|
Hi
Every control has a ContextMenu property (in framework 1.1) that you can pass a context menu to it and every time you right click on your control the context menu will be shown( you don't have to implement any mouse event)
The tree view control has a image list property that you can pass an image list to it and then you can select the image of a node by setting its ImageIndex property (aNode.ImageIndex=1 for example)
The tree view control has a Nodes collection property that contains all the modes that have been added to a treeview and you can add or remove nodes to it and each node has a nodes collection too that has the same funcionality.
Take a look at http://msdn2.microsoft.com/en-us/library/ch6etkw4.aspx[^]
Regards
|
|
|
|
|
I want to remove the title bar so I can customise the look of a form (e.g. windows live messenger).
But when I set formborderstyle to "None" the form behaves differently;
- The taskbar button looses its menu when you right click it,
- You can't minimize the window by clicking on its taskbar button
- It goes to full screen when you maximize it.
Can anyone suggest a way to sort these problems or provide an alternate way to remove the form boarder that doesn't cause these problems?
Thanks
ps. setting the region of the form solves this problem but I cant find a way to find the correct region as the dimensions of the title bar can vary.
|
|
|
|
|
Hi Sanstrom.
Try changing the property "ControlBox" follow of "FormBorderStyle"
SINCERELY.
ANTHONY ACUÑA
PREFERED PHRASE:
SOMEBODY TELL ME WHY IS MORE REAL WHEN I DREAM THAT I AM WAKE?
|
|
|
|
|
I've developed my app using C# and SLQ Server 2005 Express. Now near it's completion, I've just realised I need to create a set-up program that not only deploys my app, but ensure SQLServer Express is also installed, set-up, configured with my database and a default user ready for my App to run straight away.
Where do I start as the end users of my product will not necessarily be IT literate?
Andy
|
|
|
|
|
use the Launch Conditions option
SINCERELY.
ANTHONY ACUÑA
PREFERED PHRASE:
SOMEBODY TELL ME WHY IS MORE REAL WHEN I DREAM THAT I AM WAKE?
|
|
|
|
|
Again, assuming my users have no in-depth technical knowledge of computers, i.e. local or network installation. Although the pre-requisites alow me to select and install SQL Express, I can't seem to alter the installation process i.e. force the type of installation, instance name, auto create a user etc.. Do I need to write my own specific installation/set-up windows? If so what's the best site to learn how to alter the set-up.
Andy
|
|
|
|
|
Hi, I wonder if someone can help, please.
I am coding up a web application using ASP, C#, and a bit of javascript, and wish to enable videos from the server to be played in a popup window. I am using Windows Media Player.
Two specific questions I have:
1. I want the video to start playing automatically as soon as possible after the popup window opens, and so want to make use of the video buffer to stream. At the moment, however, the video loads but won’t start playing until the video is fully loaded. I have noticed that the windows media player is not displaying at the bottom of the player the fact that it is buffering, and wonder if anyone can help. I probably need to change some default parameters when popping up the window and running windows media player? Any ideas?
2. Also, I’d like to show a 'gallery' of videos that are available, similar in principle to that shown in windows explorer when viewing a directory of videos. I’d like the first frame of a video to be displayed to give some indication of content, and I wonder if anyone knows how to do that without going to the trouble of playing the first frame, capturing it, and displaying it as a static graphic. Any ideas?
Great if you can help !
|
|
|
|
|
Welcome to The Code Project.
Please don't post the same question in more than one forum. If you think that it is relevant for more than one forum, post it in the most relevant one, and post a link to the thread in the others.
---
b { font-weight: normal; }
|
|
|
|
|
hey,
im also working on something similar, I need to stream video to a client from my server, how do i do that? i need a sample code.
thanks,
|
|
|
|
|
i posted about how to pass my parameter to Crystalreports and a person reply to me by this code :
crystalReport11.SetDataSource(MyDataSet);
crystalReport11.SetParameterValue("PrintDate1", "2006/05/07"); // this line that error occured
crystalReportViewer1.ReportSource = crystalReport11;
but the following error shown me :
Invalid index. (Exception from HRESULT: 0x8002000B (DISP_E_BADINDEX))
how to solve my problem and pass my parameter to crystalreports ?
thanks
|
|
|
|