|
Here you go!
[Flags]
public enum MouseEvent : uint
{
MOUSEEVENTF_MOVE = 0x0001,
MOUSEEVENTF_LEFTDOWN = 0x0002,
MOUSEEVENTF_LEFTUP = 0x0004,
MOUSEEVENTF_RIGHTDOWN = 0x0008,
MOUSEEVENTF_RIGHTUP = 0x0010,
MOUSEEVENTF_MIDDLEDOWN = 0x0020,
MOUSEEVENTF_MIDDLEUP = 0x0040,
MOUSEEVENTF_XDOWN = 0x0080,
MOUSEEVENTF_XUP = 0x0100,
MOUSEEVENTF_WHEEL = 0x0800,
MOUSEEVENTF_VIRTUALDESK = 0x4000,
MOUSEEVENTF_ABSOLUTE = 0x8000
}
public enum InputType : uint
{
INPUT_MOUSE = 0,
INPUT_KEYBOARD = 1,
INPUT_HARDWARE = 2
}
[StructLayout(LayoutKind.Sequential)]
public struct MOUSEINPUT
{
private InputType type;
public UInt32 dx;
public UInt32 dy;
public UInt32 mouseData;
public MouseEvent dwFlags;
public UInt32 time;
public IntPtr dwExtraInfo;
}
public static class MouseInput
{
[DllImport("User32.dll")]
public static extern UInt32 SendInput(UInt32 nInputs, MOUSEINPUT[] pInputs, int cbSize);
private static Point Normalize(Point pt)
{
return new Point((pt.X * 65535) / Screen.PrimaryScreen.Bounds.Width,
(pt.Y * 65535) / Screen.PrimaryScreen.Bounds.Height);
}
public static void Move(Point pt)
{
pt = Normalize(pt);
MOUSEINPUT[] input = new MOUSEINPUT[1];
input[0].dx = Convert.ToUInt32(pt.X);
input[0].dy = Convert.ToUInt32(pt.Y);
input[0].dwFlags = MouseEvent.MOUSEEVENTF_MOVE | MouseEvent.MOUSEEVENTF_ABSOLUTE;
SendInput(1, input, Marshal.SizeOf(input[0]));
}
public static void Click(Point pt)
{
Move(pt);
pt = Normalize(pt);
MOUSEINPUT[] input = new MOUSEINPUT[2];
input[0].dx = Convert.ToUInt32(pt.X);
input[0].dy = Convert.ToUInt32(pt.Y);
input[0].dwFlags = MouseEvent.MOUSEEVENTF_LEFTDOWN | MouseEvent.MOUSEEVENTF_ABSOLUTE;
input[1].dx = Convert.ToUInt32(pt.X);
input[1].dy = Convert.ToUInt32(pt.Y);
input[1].dwFlags = MouseEvent.MOUSEEVENTF_LEFTUP | MouseEvent.MOUSEEVENTF_ABSOLUTE;
SendInput(2, input, Marshal.SizeOf(input[0]));
}
} To simulate a click at 100,100 therefore you'd do this:
MouseInput.Click( new Point( 100, 100 ) ); I don't think you can do it without moving the cursor. You could save the current mouse position, click at the point where you want to click and then move right back to the saved position!
|
|
|
|
|
Hi,
Almost forgot to thank you! So.. Thanks!
Nice code
|
|
|
|
|
Hey all,
I think it is possible to reset windows password through c#, but would it be possible to compare windows password to verify the user identity?
With System.Security.Principal i can get the current windows identity but i just want to verify that the person in front of the comptuter is the real user.
In case it is not possible, just for security concerns how could i approach it?
thanks in advance...
Luis E Tineo S
|
|
|
|
|
Hi,
I guess you should search on Active Directory Services Interface (ADSI).
Regards,
Adeel
|
|
|
|
|
Hi everybody,
it exists seriously a function which stops the current time, or maybe a whole "stopwatch"-class
which calculates the time between a start and a stop...
If not, how can i use the clock() function of C/C++? It's declared into time.h
Big thanks for help
|
|
|
|
|
If your time measurement doesn't require to be very precise then you can do something like this:
<br />
DateTime starttime=DateTime.Now;<br />
DoWork();<br />
DateTime endtime=DateTime.Now;<br />
The difference between endtime and starttime will show you the duration between two moments.
However, if your measurements need to be precise then I suggest you use Stopwatch Class[^]
|
|
|
|
|
Thanks for your reply
I'll test DateTime, simple but effective
Since 1year no more coded in C# and i forgot the basic classes like DateTime ... ouch LOL
|
|
|
|
|
You are welcome
|
|
|
|
|
How can i parse a c# code?
i found "SysyTem.CodeDom.Compiler.CodeDomProvider" class which have method called "Parse" but is gives me an exception that this method is not implemented, this method is what i want.
any help??
Essam
|
|
|
|
|
Ya3sam wrote: How can i parse a c# code?
What do you mean by "parse a c# code?" Are you trying to parse a file full of strings? Are they fixed-width fields, delimited, do they use CR and/or LF?
I get all the news I need from the weather report - Paul Simon (from "The Only Living Boy in New York")
|
|
|
|
|
I think he wants parser of C# language.
[ My Blog] "Visual studio desperately needs some performance improvements. It is sometimes almost as slow as eclipse." - Rüdiger Klaehn "Real men use mspaint for writing code and notepad for designing graphics." - Anna-Jayne Metcalfe
|
|
|
|
|
How about you check out the documentation[^]?
Ya3sam wrote: is gives me an exception that this method is not implemented
From the docs: "Provides a base class for CodeDomProvider implementations. This class is abstract." Of course it throws not implemented exception, it's the base class. Follow the provided link, there is example how to parse code.
[ My Blog] "Visual studio desperately needs some performance improvements. It is sometimes almost as slow as eclipse." - Rüdiger Klaehn "Real men use mspaint for writing code and notepad for designing graphics." - Anna-Jayne Metcalfe
|
|
|
|
|
Where is the link please?
Essam
|
|
|
|
|
It's word "documentation" in first sentence of my previous post. Click on it
[ My Blog] "Visual studio desperately needs some performance improvements. It is sometimes almost as slow as eclipse." - Rüdiger Klaehn "Real men use mspaint for writing code and notepad for designing graphics." - Anna-Jayne Metcalfe
|
|
|
|
|
Hi all,
Is there a C# command for me to insert date into a microsoft access database to record the date down?
I've already set the row to date/time format.
The following is the code I've written:
SQL = "INSERT INTO sent (Date, Message) VALUES ('" + DateTime.Now.Date() + "', '"+strMessage + "')";
However there still seems to be a problem as the Date still could not be recorded down into the database.
Thanks.
|
|
|
|
|
|
Use a parameterised query, then you don't have to format the values yourself:
SQL = "INSERT INTO sent (Date, Message) VALUES (@Date, @Message)";
Now add parameter objects for @Date and @Message to the command object.
If you really want to format the values yourself, you use # around dates in Access, you have to format the date in a way that the database understands (ISO 8601 is an unambigous format), and you have to encode the apostrophes in the string values:
SQL = "INSERT INTO sent (Date, Message) VALUES (#" + DateTime.Today.ToString("yyyy-MM-dd") + "#, '" + strMessage.Replace("'", "''") + "')";
Experience is the sum of all the mistakes you have done.
|
|
|
|
|
Hi there,
Since the final version will be coded in C# I thought I could just post it here. Any answers on others languages would be great too though.
I'm trying to find an algorithm that will calculate how much two Strings differ from eachother. For example, giving a score from 0-100 based on how much they are alike. I did come across the Levenshtein algorithm, but that wasn't realy what I'm looking for.
For example:
Comparing "markAdress" with "adressMark" should return a high score, since they are much alike.
Kind regards,
~Sph
|
|
|
|
|
Hi y'all,
I'm working with a two-dimensional array and i need to randomly select any element from the array at any given time. Is this possible?
Second, from an array of strings, is it possible to randomly select a string value like the System.Random class?
Thanks in advance,
Obinna from Nigeria.
//obinnaaj Eof
|
|
|
|
|
In first case just generate two random numbers which are not more then the dimension of the array and use them for indexes to access an element of the array.
In the second case generate a random number not more then the length of the array and access an element with that index
|
|
|
|
|
hi
i have a reportViewer in my form and a report in reportDesigner named 'Report1.rdlc'.
in my report, i define a parameter that has these properties :
Name = Report_Parameter_0
Data type = String
Promt = 11111111111111
Allow blank value = true
Null = true
and add a textBox to my report in reportDesigner with following properties :
Name = textbox5
Value = Parameters!Report_Parameter_0.Value
and in my form load event that show report i wrote this code to send my value to 'Report_Parameter_0' programmatically :
try
{
this.v_customerOrderCountTableAdapter.Fill(this.NorthwindDataSet.v_customerOrderCount);
Microsoft.Reporting.WinForms.ReportParameter rp = new Microsoft.Reporting.WinForms.ReportParameter("Report_Parameter_0", "Param From Code");
this.reportViewer1.LocalReport.SetParameters(new Microsoft.Reporting.WinForms.ReportParameter[] { rp });
this.reportViewer1.RefreshReport();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
with above information, in runTime, i prospected that 'textbox5' have 'Param From Code' value, but have
'Parameters!Report_Parameter_0.Value' yet.
where does problem and how to send value to reportParameter correctly ?
thanks
|
|
|
|
|
ServerReport.SetParameters Method
List<ReportParameter> paramList = new List<ReportParameter>();<br />
<br />
paramList.Add(new ReportParameter("EmpID", "288", false));<br />
paramList.Add(new ReportParameter("ReportMonth", "12", false));<br />
paramList.Add(new ReportParameter("ReportYear", "2003", false));<br />
<br />
this.reportViewer1.ServerReport.SetParameters(paramList); ??
|
|
|
|
|
I require to disable/enable check box in a property grid dynamically at runtime using C# .NET.
I was able to to disable/enable the Check box at runtime. But the problem is If I enable check box dynamically I am no longer able to select the check box. I am using TypeConvertor and UITypeEditor together to disable/enable the check box at runtime.
If I do not use TypeConvertor with UITypeEditor then I am able to select the check box.
Can anyone faced this problem ?
I am using the following Code piece:
[TypeConverter(typeof(myConverter))]
[Editor(typeof(CheckBoxInPropertyGridEditorCapex), typeof(System.Drawing.Design.UITypeEditor))]
public bool ValidForCapex
{
get { return validForCapex; }
set { validForCapex = value; }
}
public class CheckBoxInPropertyGridEditorCapex : UITypeEditor
{
public override bool GetPaintValueSupported(ITypeDescriptorContext context)
{
return true;
}
public override void PaintValue(PaintValueEventArgs e)
{
ControlPaint.DrawCheckBox(e.Graphics, e.Bounds, ((GeneralDimensionClass)e.Context.Instance).validForCapex ? ButtonState.Checked : ButtonState.Normal);
}
}
public class myConverter : StringConverter
{
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
{
if (ValidForCapexRead == true)
{
return false;
}
return base.CanConvertFrom(context, sourceType);
}
public override bool CanConvertTo(ITypeDescriptorContext context,
System.Type destinationType)
{
return base.CanConvertTo(context, destinationType);
}
}
Rajan
|
|
|
|
|
please someone help me. I need to write codes for how may days til christmax.
|
|
|
|
|
There is a complex formula for calculating that. It isn't hard to implement, just use your best friend. GOOGLE.
The best way to accelerate a Macintosh is at 9.8m/sec² - Marcus Dolengo
|
|
|
|