Positioning window form to be bottommost - c#

I want every time you start my window form, he set at the bottom of the screen (above the taskbar)
public void goBottomWindow(Form targetForm)
{
targetForm.WindowState = FormWindowState.Maximized;
targetForm.FormBorderStyle = FormBorderStyle.None;
targetForm.TopMost = true;
WinApi.SetWinFullScreen(targetForm.Handle);
}
public class WinApi
{
[DllImport("user32.dll", EntryPoint = "GetSystemMetrics")]
public static extern int GetSystemMetrics(int which);
[DllImport("user32.dll")]
public static extern void
SetWindowPos(IntPtr hwnd, IntPtr hwndInsertAfter,
int X, int Y, int width, int height, uint flags);
private const int SM_CXSCREEN = 0;
private const int SM_CYSCREEN = 1;
private static IntPtr HWND_TOP = IntPtr.Zero;
private const int SWP_SHOWWINDOW = 64; // 0x0040
public static int ScreenX
{
get { return GetSystemMetrics(SM_CXSCREEN); }
}
public static int ScreenY
{
get {return 60;}
}
public static void SetWinFullScreen(IntPtr hwnd)
{
SetWindowPos(hwnd, HWND_TOP, 0, 0, ScreenX, ScreenY, SWP_SHOWWINDOW);
}
}
Using this code, it leaves my window form at the top of the screen .... but what I need is the form window positioned below.
It is possible to do this?
Sorry, my English is very bad :(

Why targetForm.WindowState = FormWindowState.Maximized; ?
isn't FormWindowState.Normal better for you?
Just fetch the dimension of your desktop/screen
var rect = Screen.PrimaryScreen.WorkingArea;
targetForm.Witdh = rect.Width;
targetForm.Top = rect.Height - targetForm.Height;

I saw that in your first lines it says targetForm.TopMost = true;
That means that your form will be TOPMOST, if you want your form to be BottomMost, you should change that to false;
Hope this helps! - CCB

Related

Full screen windows form but with title bar

I am following this article, http://www.vesic.org/english/blog-eng/net/full-screen-maximize/
This makes my windows form to go full screen but it also hides Title bar.
I want to hide task bar but like to have my title bar.
" targetForm.FormBorderStyle = FormBorderStyle.None;" hides my title bar but removing this shows task bar so is there anyway to hide task bar and keep title bar in windows app? Thanks
using System;
using System.Drawing;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace myClasses
{
public class WinApi
{
[DllImport("user32.dll", EntryPoint = "GetSystemMetrics")]
public static extern int GetSystemMetrics(int which);
[DllImport("user32.dll")]
public static extern void
SetWindowPos(IntPtr hwnd, IntPtr hwndInsertAfter,
int X, int Y, int width, int height, uint flags);
private const int SM_CXSCREEN = 0;
private const int SM_CYSCREEN = 1;
private static IntPtr HWND_TOP = IntPtr.Zero;
private const int SWP_SHOWWINDOW = 64; // 0x0040
public static int ScreenX
{
get { return GetSystemMetrics(SM_CXSCREEN); }
}
public static int ScreenY
{
get { return GetSystemMetrics(SM_CYSCREEN); }
}
public static void SetWinFullScreen(IntPtr hwnd)
{
SetWindowPos(hwnd, HWND_TOP, 0, 0, ScreenX, ScreenY, SWP_SHOWWINDOW);
}
}
/// <summary>
/// Class used to preserve / restore state of the form
/// </summary>
public class FormState
{
private FormWindowState winState = FormWindowState.Normal;
private FormBorderStyle brdStyle = FormBorderStyle.Sizable;
private bool topMost;
private Rectangle bounds;
private bool IsMaximized = false;
public void Maximize(Form targetForm)
{
if (!IsMaximized)
{
IsMaximized = true;
Save(targetForm);
targetForm.WindowState = FormWindowState.Maximized;
targetForm.FormBorderStyle = FormBorderStyle.None;
//targetForm.TopMost = true;
WinApi.SetWinFullScreen(targetForm.Handle);
}
}
public void Save(Form targetForm)
{
winState = targetForm.WindowState;
brdStyle = targetForm.FormBorderStyle;
topMost = targetForm.TopMost;
bounds = targetForm.Bounds;
}
public void Restore(Form targetForm)
{
targetForm.WindowState = winState;
targetForm.FormBorderStyle = brdStyle;
targetForm.TopMost = topMost;
targetForm.Bounds = bounds;
IsMaximized = false;
}
}
}
You can set it to FormBorderStyle.FixedToolWindow;, than only the taskbar is hidden.

Attach WPF Window to the Window of Another Process

I want to write a WPF application that docks to an application running in another process (this is a 3rd party app I have no control of). Ideally I would like to be able to define if the app docks on the left or right.
Here's an example of what I want to do:
I have tried to implement the following 2 examples with no success.
Attach window to window of another process - Button_Click gives the following error:
Attach form window to another window in C# - Button_Click_1 docks it the title bar but I cannot see the entire app:
The following is the code:
namespace WpfApplicationTest
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
[DllImport("user32.dll")]
public static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);
[DllImport("user32.dll")]
public static extern int GetWindowLong(IntPtr hWnd, int nIndex);
[DllImport("user32.dll", SetLastError = true)]
private static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);
public static int GWL_STYLE = -16;
public static int WS_CHILD = 0x40000000;
[DllImport("user32")]
private static extern bool SetWindowPos(
IntPtr hWnd,
IntPtr hWndInsertAfter,
int x,
int y,
int cx,
int cy,
uint uFlags);
private IntPtr _handle;
private void SetBounds(int left, int top, int width, int height)
{
if (_handle == IntPtr.Zero)
_handle = new WindowInteropHelper(this).Handle;
SetWindowPos(_handle, IntPtr.Zero, left, top, width, height, 0);
}
public MainWindow()
{
InitializeComponent();
}
private void Button_Click(object sender, RoutedEventArgs e)
{
Process hostProcess = Process.GetProcessesByName("notepad").FirstOrDefault();
IntPtr hostHandle = hostProcess.MainWindowHandle;
//MyWindow window = new MyWindow();
this.ShowActivated = true;
HwndSourceParameters parameters = new HwndSourceParameters();
parameters.WindowStyle = 0x10000000 | 0x40000000;
parameters.SetPosition(0, 0);
parameters.SetSize((int)this.Width, (int)this.Height);
parameters.ParentWindow = hostHandle;
parameters.UsesPerPixelOpacity = true;
HwndSource src = new HwndSource(parameters);
src.CompositionTarget.BackgroundColor = Colors.Transparent;
src.RootVisual = (Visual)this.Content;
}
private void Button_Click_1(object sender, RoutedEventArgs e)
{
Process hostProcess = Process.GetProcessesByName("notepad").FirstOrDefault();
if (hostProcess != null)
{
Hide();
//this.WindowStyle;
//new WindowInteropHelper(this).SetBounds(0, 0, 0, 0, BoundsSpecified.Location);
//SetWindowPos(new WindowInteropHelper(this).Handle, IntPtr.Zero, 0, 0, 0, 0, 0);
SetBounds(0, 0, 0, 0);
IntPtr hostHandle = hostProcess.MainWindowHandle;
IntPtr guestHandle = new WindowInteropHelper(this).Handle;
SetWindowLong(guestHandle, GWL_STYLE, GetWindowLong(guestHandle, GWL_STYLE) | WS_CHILD);
SetParent(guestHandle, hostHandle);
Show();
}
}
}
You implementation is totally wrong, you are trying to make your window as a child window of the window you want to snap to.
I wrote a small helper class for snapping to another window by it's title, I hope this helps.
WindowSnapper.cs
public class WindowSnapper
{
private struct Rect
{
public int Left { get; set; }
public int Top { get; set; }
public int Right { get; set; }
public int Bottom { get; set; }
public int Height
{
get { return Bottom - Top; }
}
public static bool operator !=(Rect r1, Rect r2)
{
return !(r1 == r2);
}
public static bool operator ==(Rect r1, Rect r2)
{
return r1.Left == r2.Left && r1.Right == r2.Right && r1.Top == r2.Top && r1.Bottom == r2.Bottom;
}
}
[DllImport("user32.dll")]
private static extern bool GetWindowRect(IntPtr hwnd, ref Rect rectangle);
private DispatcherTimer _timer;
private IntPtr _windowHandle;
private Rect _lastBounds;
private Window _window;
private string _windowTitle;
public WindowSnapper(Window window, String windowTitle)
{
_window = window;
_window.Topmost = true;
_windowTitle = windowTitle;
_timer = new DispatcherTimer();
_timer.Interval = TimeSpan.FromMilliseconds(10);
_timer.Tick += (x, y) => SnapToWindow();
_timer.IsEnabled = false;
}
public void Attach()
{
_windowHandle = GetWindowHandle(_windowTitle);
_timer.Start();
}
public void Detach()
{
_timer.Stop();
}
private void SnapToWindow()
{
var bounds = GetWindowBounds(_windowHandle);
if (bounds != _lastBounds)
{
_window.Top = bounds.Top;
_window.Left = bounds.Left - _window.Width;
_window.Height = bounds.Height;
_lastBounds = bounds;
}
}
private Rect GetWindowBounds(IntPtr handle)
{
Rect bounds = new Rect();
GetWindowRect(handle, ref bounds);
return bounds;
}
private IntPtr GetWindowHandle(string windowTitle)
{
foreach (Process pList in Process.GetProcesses())
{
if (pList.MainWindowTitle.Contains(windowTitle))
{
return pList.MainWindowHandle;
}
}
return IntPtr.Zero;
}
}
Usage example:
public partial class MainWindow : Window
{
private WindowSnapper _snapper;
public MainWindow()
{
InitializeComponent();
_snapper = new WindowSnapper(this, "Notepad");
_snapper.Attach();
}
}

How to modify the default size of System.Windows.Forms.FolderBrowserDialog? It's too small if you don't modify it by hand

I want the FolderBrowserDialog to be larger when first shown so that it can show more than three-level directory. Is that anyway to do it or is there anyway to override a similiar dialog?
I shamelessly copied Hans's code and modified it to achieve what you want.
private void button1_Click(object sender, EventArgs e)
{
using (new SizeWinDialog(this)//This refers to wpf Window
{
PreferredSize = new Size(150, 150)//Change this size to whatever you want
})
{
FolderBrowserDialog fbd = new FolderBrowserDialog();
fbd.ShowDialog();
}
}
class SizeWinDialog : IDisposable
{
private int mTries = 0;
private Window mOwner;
public SizeWinDialog(Window owner)
{
mOwner = owner;
owner.Dispatcher.BeginInvoke(new Action(findDialog));
}
public Size PreferredSize { get; set; }
private void findDialog()
{
// Enumerate windows to find the message box
if (mTries < 0) return;
EnumThreadWndProc callback = new EnumThreadWndProc(checkWindow);
if (EnumThreadWindows(GetCurrentThreadId(), callback, IntPtr.Zero))
{
if (++mTries < 10) mOwner.Dispatcher.BeginInvoke(new MethodInvoker(findDialog));
}
}
private bool checkWindow(IntPtr hWnd, IntPtr lp)
{
// Checks if <hWnd> is a dialog
StringBuilder sb = new StringBuilder(260);
GetClassName(hWnd, sb, sb.Capacity);
if (sb.ToString() != "#32770") return true;
// Got it
RECT dlgRect;
GetWindowRect(hWnd, out dlgRect);
SetWindowPos(new HandleRef(this, hWnd), new HandleRef(), dlgRect.Left, dlgRect.Top, PreferredSize.Width, PreferredSize.Height, 20 | 2);
return false;
}
public void Dispose()
{
mTries = -1;
}
// P/Invoke declarations
private delegate bool EnumThreadWndProc(IntPtr hWnd, IntPtr lp);
[DllImport("user32.dll")]
private static extern bool EnumThreadWindows(int tid, EnumThreadWndProc callback, IntPtr lp);
[DllImport("kernel32.dll")]
private static extern int GetCurrentThreadId();
[DllImport("user32.dll")]
private static extern int GetClassName(IntPtr hWnd, StringBuilder buffer, int buflen);
[DllImport("user32.dll")]
private static extern bool GetWindowRect(IntPtr hWnd, out RECT rc);
[DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)]
public static extern bool SetWindowPos(HandleRef hWnd, HandleRef hWndInsertAfter, int x, int y, int cx, int cy,
int flags);
private struct RECT { public int Left; public int Top; public int Right; public int Bottom; }
}
I converted the code sample above back to WinForms from the WPF version that is shown. I also created two companion classes that will size a system dialog and will place it at a specific offset from the parent form. They are used like this:
using (new OffsetWinDialog(this) { PreferredOffset = new Point(75, 75 )})
using (new SizeWinDialog(this) { PreferredSize = new Size(400, 600)})
{
DialogResult result = dlgFolderBrowser.ShowDialog();
if (result == DialogResult.Cancel)
return;
}
The original post (below) shows how to place the system dialog at the center of the parent. Together, these three classes will let you control the initial size and position of the system dialogs. Rather than repeat the code here, please refer to the following thread.
Winforms-How can I make MessageBox appear centered on MainForm?

C# Transparent GUI

Hey all. i was wondering how would i make a GUI that is "transparent" in C#. Now im not talking about transparencykey etc.
I want to make a window that uses vistas aero theme but instead of a control in the form i just want it to show more of that seethru aero look. And also i want to remove all buttons and icons and text from the window. How would i do this?
EDIT... I found a PERFECT example of what i want to create. Load up the windows mobility center on vista. How can i create something like that but without the boxes in it.
How to Glass into your Client Area
Here is the API I used when I did this for our Windows app a few years ago.
Check out the method ExtendGlassIntoClientArea(Form form, int leftMargin, int topMargin, int rightMargin, int bottomMargin)
using System;
using System.Drawing;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace UserInterface
{
public enum TextStyle
{
Normal,
Glowing
}
public static class Glass
{
[DllImport("dwmapi.dll")]
private static extern void DwmIsCompositionEnabled(ref bool pfEnabled);
[DllImport("dwmapi.dll")]
private static extern void DwmExtendFrameIntoClientArea(IntPtr hWnd, ref MARGINS pMargins);
[DllImport("gdi32.dll", ExactSpelling = true, SetLastError = true)]
private static extern IntPtr CreateCompatibleDC(IntPtr hDC);
[DllImport("gdi32.dll", ExactSpelling = true)]
private static extern IntPtr SelectObject(IntPtr hDC, IntPtr hObject);
[DllImport("gdi32.dll", ExactSpelling = true, SetLastError = true)]
private static extern bool DeleteObject(IntPtr hObject);
[DllImport("gdi32.dll", ExactSpelling = true, SetLastError = true)]
private static extern bool DeleteDC(IntPtr hdc);
[DllImport("gdi32.dll")]
private static extern bool BitBlt(IntPtr hdc, int nXDest, int nYDest, int nWidth, int nHeight, IntPtr hdcSrc, int nXSrc, int nYSrc, uint dwRop);
[DllImport("UxTheme.dll", CharSet = CharSet.Unicode)]
private static extern int DrawThemeTextEx(IntPtr hTheme, IntPtr hdc, int iPartId, int iStateId, string text, int iCharCount, int dwFlags, ref RECT pRect, ref DTTOPTS pOptions);
[DllImport("gdi32.dll")]
static extern IntPtr CreateDIBSection(IntPtr hdc, [In] ref BITMAPINFO pbmi, uint iUsage, out IntPtr ppvBits, IntPtr hSection, uint dwOffset);
[StructLayout(LayoutKind.Sequential)]
private struct DTTOPTS
{
public int dwSize;
public int dwFlags;
public int crText;
public int crBorder;
public int crShadow;
public int iTextShadowType;
public POINT ptShadowOffset;
public int iBorderSize;
public int iFontPropId;
public int iColorPropId;
public int iStateId;
public bool fApplyOverlay;
public int iGlowSize;
public int pfnDrawTextCallback;
public IntPtr lParam;
}
private const int DTT_COMPOSITED = 8192;
private const int DTT_GLOWSIZE = 2048;
private const int DTT_TEXTCOLOR = 1;
[StructLayout(LayoutKind.Sequential)]
private struct POINT
{
public POINT(int x, int y)
{
this.x = x;
this.y = y;
}
public int x;
public int y;
}
[StructLayout(LayoutKind.Sequential)]
private class BITMAPINFO
{
public int biSize;
public int biWidth;
public int biHeight;
public short biPlanes;
public short biBitCount;
public int biCompression;
public int biSizeImage;
public int biXPelsPerMeter;
public int biYPelsPerMeter;
public int biClrUsed;
public int biClrImportant;
public byte bmiColors_rgbBlue;
public byte bmiColors_rgbGreen;
public byte bmiColors_rgbRed;
public byte bmiColors_rgbReserved;
}
[StructLayout(LayoutKind.Sequential)]
private struct MARGINS
{
public int left, right, top, bottom;
}
[StructLayout(LayoutKind.Sequential)]
private struct RECT
{
public int Left;
public int Top;
public int Right;
public int Bottom;
public RECT(int left, int top, int right, int bottom)
{
Left = left;
Top = top;
Right = right;
Bottom = bottom;
}
public RECT(Rectangle rectangle)
{
Left = rectangle.X;
Top = rectangle.Y;
Right = rectangle.Right;
Bottom = rectangle.Bottom;
}
public Rectangle ToRectangle()
{
return new Rectangle(Left, Top, Right - Left, Bottom - Top);
}
public override string ToString()
{
return "Left: " + Left + ", " + "Top: " + Top + ", Right: " + Right + ", Bottom: " + Bottom;
}
}
public static bool IsCompositionEnabled
{
get
{
if (Environment.OSVersion.Version.Major < 6)
return false;
bool compositionEnabled = false;
DwmIsCompositionEnabled(ref compositionEnabled);
return compositionEnabled;
}
}
public static void ExtendGlassIntoClientArea(Form form, int leftMargin, int topMargin, int rightMargin, int bottomMargin)
{
MARGINS m = new MARGINS();
m.left = leftMargin;
m.right = rightMargin;
m.top = topMargin;
m.bottom = bottomMargin;
DwmExtendFrameIntoClientArea(form.Handle, ref m);
}
public static void DrawText(Graphics graphics, string text, Font font, Rectangle bounds, Color color, TextFormatFlags flags)
{
DrawText(graphics, text, font, bounds, color, flags, TextStyle.Normal);
}
public static void DrawText(Graphics graphics, string text, Font font, Rectangle bounds, Color color, TextFormatFlags flags, TextStyle textStyle)
{
IntPtr primaryHdc = graphics.GetHdc();
// Create a memory DC so we can work offscreen
IntPtr memoryHdc = CreateCompatibleDC(primaryHdc);
// Create a device-independent bitmap and select it into our DC
BITMAPINFO info = new BITMAPINFO();
info.biSize = Marshal.SizeOf(info);
info.biWidth = bounds.Width;
info.biHeight = -bounds.Height;
info.biPlanes = 1;
info.biBitCount = 32;
info.biCompression = 0; // BI_RGB
int ppvBits;
IntPtr dib = CreateDIBSection(primaryHdc, ref info, 0, out ppvBits, IntPtr.Zero, 0);
SelectObject(memoryHdc, dib);
// Create and select font
IntPtr fontHandle = font.ToHfont();
SelectObject(memoryHdc, fontHandle);
// Draw glowing text
System.Windows.Forms.VisualStyles.VisualStyleRenderer renderer = new System.Windows.Forms.VisualStyles.VisualStyleRenderer(System.Windows.Forms.VisualStyles.VisualStyleElement.Window.Caption.Active);
DTTOPTS dttOpts = new DTTOPTS();
dttOpts.dwSize = Marshal.SizeOf(typeof(DTTOPTS));
if (textStyle == TextStyle.Glowing)
{
dttOpts.dwFlags = DTT_COMPOSITED | DTT_GLOWSIZE | DTT_TEXTCOLOR;
}
else
{
dttOpts.dwFlags = DTT_COMPOSITED | DTT_TEXTCOLOR;
}
dttOpts.crText = ColorTranslator.ToWin32(color);
dttOpts.iGlowSize = 8; // This is about the size Microsoft Word 2007 uses
RECT textBounds = new RECT(0, 0, bounds.Right - bounds.Left, bounds.Bottom - bounds.Top);
DrawThemeTextEx(renderer.Handle, memoryHdc, 0, 0, text, -1, (int)flags, ref textBounds, ref dttOpts);
// Copy to foreground
const int SRCCOPY = 0x00CC0020;
BitBlt(primaryHdc, bounds.Left, bounds.Top, bounds.Width, bounds.Height, memoryHdc, 0, 0, SRCCOPY);
// Clean up
DeleteObject(fontHandle);
DeleteObject(dib);
DeleteDC(memoryHdc);
graphics.ReleaseHdc(primaryHdc);
}
}
}
if WPF, it's a matter of turning transparency on, and setting the right values for the background (additionally, WPF supports AERO natively for borders and what-not).
For traditional winforms... things start getting hard.
plus there's always Form.Opacity property of the windows Form.
Have you tried to check out this which was referred in another question?

Control another application using C#

I need to control other application by simulating mouse movement and keyboard input. How do I accomplish this in C#? Is it even possible?
Have you looked at White TestStack?
Sample code:
Application application = Application.Launch("foo.exe");
Window window = application.GetWindow("bar", InitializeOption.NoCache);
Button button = window.Get<Button>("save");
button.Click();
I don't think it can get better than that. The library is created by ThoughtWorks.
See "To send a keystroke to a different application" on this page:
http://msdn.microsoft.com/en-us/library/ms171548.aspx
You can use p/invoke, I stole the following code for mouse clicks in random spots on a button with a known handle:
[Flags]
public enum MouseEventFlags
{
LEFTDOWN = 0x00000002,
LEFTUP = 0x00000004,
MIDDLEDOWN = 0x00000020,
MIDDLEUP = 0x00000040,
MOVE = 0x00000001,
ABSOLUTE = 0x00008000,
RIGHTDOWN = 0x00000008,
RIGHTUP = 0x00000010
}
[StructLayout(LayoutKind.Sequential)]
public struct Rectangle
{
public int X;
public int Y;
public int Width;
public int Height;
}
private static void Click(IntPtr Handle)
{
lock (typeof(MouseAction))
{
Rectangle buttonDesign;
GetWindowRect(Handle, out buttonDesign);
Random r = new Random();
int curX = 10 + buttonDesign.X + r.Next(100 - 20);
int curY = 10 + buttonDesign.Y + r.Next(60 - 20);
SetCursorPos(curX, curY);
//Mouse Right Down and Mouse Right Up
mouse_event((uint)MouseEventFlags.LEFTDOWN, curX, curY, 0, 0);
mouse_event((uint)MouseEventFlags.LEFTUP, curX, curY, 0, 0);
}
}
[DllImport("user32.dll")]
static extern bool SetCursorPos(int X, int Y);
[DllImport("user32.dll")]
private static extern void mouse_event(
long dwFlags, long dx, long dy, long cButtons, long dwExtraInfo);
[DllImport("user32.dll")]
static extern bool GetWindowRect(IntPtr hWnd, out Rectangle rect);
you can use AutoIT, it's freeware, and it has a dll version that you can import into C# (DllImport). It allows you to click on controls, write strings to edit boxes, make combobox selections etc on another application from C#.
Use the SendMessage Native Win32 API. DllImport this method from the User32.dll. You can use this API to send both keyboard & mouse messages
I tried to do the same: to use the mouse i used this class
(you need to add using System.Runtime.InteropServices;)
public class MouseClick1 //public is important here**
{
[DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
public static extern void mouse_event(uint dwFlags, uint dx, uint dy, uint cButtons, uint dwExtraInfo);
private const int MOUSEEVENTF_LEFTDOWN = 0x02;
private const int MOUSEEVENTF_LEFTUP = 0x04;
private const int MOUSEEVENTF_RIGHTDOWN = 0x08;
private const int MOUSEEVENTF_RIGHTUP = 0x10;
public int CoordX { get; set; }
public int CoordY { get; set; }
public void Click1()
{
Cursor.Position = new Point(CoordX, CoordY);
mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
}
}
and after on your form1 (presuming the name is form1) you can
public partial class form1 : Form
{
MouseClick1 button1 = new MouseClick1();
MouseClick1 button2 = new MouseClick1();
[...]
public void Simulate_button1and2_Click(object sender, EventArgs e)
{
button1.CoordX = 1652; //random coordinates
button1.CoordY = 225;
button2.CoordX = 1650;
button2.CoordY = 250;
button1.Click1();
button1.Click2();
}
}
To have the coordinates on your pointer, I use a timer and a label:
private void timer1_Tick(object sender, EventArgs e)
{
Coord.Text = Cursor.Position.X.ToString() + " : " + Cursor.Position.Y.ToString(); //Premet d'avoir les coord en direct
}
Work fine with me.

Categories