|
Good Luck!
That's about all I can say as you haven't asked a question.
|
|
|
|
|
|
Hello
How I can find selected control on any window from mouse click c#
I want to snapshot the object when mouse click
thanks
|
|
|
|
|
Try
private void Control_Clicks(object sender, EventArgs e)
{
Control control = (Control)sender;
MessageBox.Show(control.Name.ToString());
}
|
|
|
|
|
see this
IntPtr hWnd = WindowFromPoint(Control.MousePosition);
if (hWnd != IntPtr.Zero)
{
Control ctl = Control.FromHandle(hWnd);
if (ctl != null)
label1.Text = ctl.Name;
}
it works inside the form I need it ouside the form to snapshot the control when mouse click.
thanks
|
|
|
|
|
That's not going to work. Control will only work with windows in your application.
I take it you're trying to get a screenshot of any window? BTW, every control is its own little window, not just the large thing you see with a titlebar and a bunch of controls on it and drag around.
You can't do what you want using the .NET classes. You have to P/Invoke Win32 functions to do this. For a good example, look at this[^], which refers to this library[^].
|
|
|
|
|
I do not want to snapshot window or fullscreen or region,I want snapshot object when mouse click on that object.
Object capture. The object can be window, control, windows shortcut menu etc.
|
|
|
|
|
You'd need to dive into the WinAPI; getting access to a window (on a low level, everything, including textboxes and buttons, are windows) using it's handle. You'd not be able to map a TButton (from a Delphi App) to a .NET Button, but you should be able to get the dimensions of the window. That is, assuming that it is based on a window.
See, there was a time when these things were expensive and Windows would run out of handles. The easiest solution to lower the amount of windows used in an application was to get rid of the labels and to draw them by hand. You'll find that there's a lot of older apps (and newer games!) that don't use the common control-library at all. If I draw a fake button on a panel and handle a mouse-click on that location as if it were a button, you'd see a button as a user, but would never find one on the form.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
You are going to need to set a Global Mouse Hook. There's an excellent article here on CP, since 2004 !, by George Mamaladze on how to do this: [^].
If, by "snapshot" the clicked Control, you mean do a bitmap screen capture: yes, as Dave K. said, you are going to get into heavy use of the Win API and Platform Invoke. Search CodeProject for articles on screen capture.
I suspect (but don't have personal experience with) that once you know the Window (the app) that got the Click, that getting hold of the Control will require some clever coding.
"What Turing gave us for the first time (and without Turing you just couldn't do any of this) is he gave us a way of thinking about and taking seriously and thinking in a disciplined way about phenomena that have, as I like to say, trillions of moving parts.
Until the late 20th century, nobody knew how to take seriously a machine with a trillion moving parts. It's just mind-boggling." Daniel C. Dennett
|
|
|
|
|
thanks for your help my friends
I already see the code but it has some issues.
so if you find away to take snapshot of object when mouse click
do not forget me.
thanks again friends
|
|
|
|
|
For an article on capturing a specified portion of the screen - see this article clickety[^] by yours truly.
“That which can be asserted without evidence, can be dismissed without evidence.”
― Christopher Hitchens
|
|
|
|
|
Hi there,
my question is what might fit better to storing objects.
I have a routine where i save ListViewItems and another for storing objects (selfmade class Resource) into a Dictionary.
But my collegue told me i should use a List<> because they are better.
I missed the why they are better.
So anyone can explain me why they should be better and whats the significant difference?
EDIT:
To explain more specific:
I need a container to store objects of my models that will be generated by Loops according to the data provided by my database.
e.g.:
I have a class Resource
public class Resource
{
MSSQL _dbIMS = null;
SqlGenerator _sqlGenerator = null;
private string _name = "";
private string _firstName = "";
private string _idEmployee = "";
private string _idCalendar = "";
private string _idBenDivFaeh = "";
private string _personalID = "";
private string _phoneNumber = "";
private string _costCentre = "";
private double _costsPerHour = 0.0;
private string _idDivision = "";
private bool _modified = false;
This will be generated after i loaded the values out of the database. Those objects then need to be stored somewhere so i can add them to a ListView.
Later on i will have those ListViewItems related to a advTree with projects and to another with divisions, the ListViewItems can be dragged and dropped onto the advTrees to modify the relation to a division for example.
So where to store the objects of the resource? List or Dictionary?
I hope this is a better explanation
Thanks in advance
if(this.signature != "")
{
MessageBox.Show("This is my signature: " + Environment.NewLine + signature);
}
else
{
MessageBox.Show("404-Signature not found");
}
modified 10-Dec-13 4:32am.
|
|
|
|
|
Explanation about Dictionaries[^]
You haven't provided much info about why you think you need to use a Dictionary - There is a reason why they exist, but there is also a reason why a List type exists.
Dictionaries are usually used to bind unrelated objects - If you need no binding to unrelated objects you better use a List.
A Dictionary may be useful if you want to pair numbers with their textual representation (1 = one, 2= two) etc. but it is going to fail on you if you need to store complex objects.
Veni, vidi, caecus
|
|
|
|
|
List and Dictionary are meant for completely different purposes. It's like saying which is best, Beethoven or a horse? You store the objects in the container that best fits your needs. So, if you need a keyed lookup of your objects for efficient retrieval, a Dictionary is a better bet than a List. If, however, all you need is somewhere to store data and you aren't that bothered about searching for it, a List is a good choice.
|
|
|
|
|
thanks for the explanations and for the great article about dictionarys.
if(this.signature != "")
{
MessageBox.Show("This is my signature: " + Environment.NewLine + signature);
}
else
{
MessageBox.Show("404-Signature not found");
}
|
|
|
|
|
Just to add to Pete's answer, you might want to Google for tutorials on "data structures" (which both Lists and Dictionaries are). Each has it own uses, and you can save yourself a stack* of work using the correct one. In my experience List and Dictionary are the two I most commonly use c#, but YMMV, it's worth knowning about the others.
*intended.
|
|
|
|
|
Pete O'Hanlon wrote: List and Dictionary are meant for completely different purposes. It's like saying which is best, Beethoven or a horse? +500
/ravi
|
|
|
|
|
It's often the case that where you want a mapping between items of different Types, such as ListViewItems in a ListView, and instances of your own Classes, that a Dictionary is a very convenient way to enable rapid access from an instance of one Type to the related instance of the other Type ... without casting, or too-clever coding.
A good example would be a combination ListView and TreeView Control: by keeping a Dictionary<ListViewItem, TreeNode>, and a "symmetric" Dictionary<TreeNode, ListViewItem>, you can rapidly synchronize the selection in both TreeView and ListView without translating indexes from one to the other, casting, etc.
"What Turing gave us for the first time (and without Turing you just couldn't do any of this) is he gave us a way of thinking about and taking seriously and thinking in a disciplined way about phenomena that have, as I like to say, trillions of moving parts.
Until the late 20th century, nobody knew how to take seriously a machine with a trillion moving parts. It's just mind-boggling." Daniel C. Dennett
|
|
|
|
|
i wanna to show this xml in textbox (same as .xml file) (xml format) and be able to edit it and save.
note : if possible to import this xml to Datagridview:
DataSet ds = new DataSet();
StringReader rr = new StringReader("<root> <steps><step number=\"1\"><positions><position id=\"21\" /><position id=\"19\" /></positions><persons><person id=\"37\" position=\"21\"><systemfolder>4</systemfolder><controls><control fieldname=\"قسمت درخواست مرخصي\" fieldlatinname=\"request part for vacation\" fieldcontrolname=\"pnldarkhast\" editable=\"true\" visible=\"true\" /><control fieldname=\"بخش مربوط به مدير قسمت\" fieldlatinname=\"supervisor part\" fieldcontrolname=\"pnlmodir\" editable=\"false\" visible=\"false\" /><control fieldname=\"چرخه دارد\" fieldlatinname=\"is workflow\" fieldcontrolname=\"checkbox_isworkflow\" editable=\"false\" visible=\"false\" /><control fieldname=\"قسمت مربوط به کار گزيني\" fieldlatinname=\"human resource part\" fieldcontrolname=\"pnlkargozeni\" editable=\"false\" visible=\"false\" /><control fieldname=\"ساعت باقي مانده\" fieldlatinname=\"remain hours\" fieldcontrolname=\"pnlvacationhoursremain\" editable=\"false\" visible=\"true\" /></controls><permissions><activities><start>false</start><pause>false</pause><stop>false</stop></activities><backpermission>False</backpermission><selectablepersons>False</selectablepersons><selectableSender>False</selectableSender><selectableStarter>False</selectableStarter><ViewProcess>False</ViewProcess><ViewFinalTillNow>False</ViewFinalTillNow><CanSendToOthers>False</CanSendToOthers><attachfile>True</attachfile></permissions></person><person id=\"28\" position=\"19\"><systemfolder>4</systemfolder><controls><control fieldname=\"قسمت درخواست مرخصي\" fieldlatinname=\"request part for vacation\" fieldcontrolname=\"pnldarkhast\" editable=\"true\" visible=\"true\" /><control fieldname=\"بخش مربوط به مدير قسمت\" fieldlatinname=\"supervisor part\" fieldcontrolname=\"pnlmodir\" editable=\"false\" visible=\"false\" /><control fieldname=\"چرخه دارد\" fieldlatinname=\"is workflow\" fieldcontrolname=\"checkbox_isworkflow\" editable=\"false\" visible=\"false\" /><control fieldname=\"قسمت مربوط به کار گزيني\" fieldlatinname=\"human resource part\" fieldcontrolname=\"pnlkargozeni\" editable=\"false\" visible=\"false\" /><control fieldname=\"ساعت باقي مانده\" fieldlatinname=\"remain hours\" fieldcontrolname=\"pnlvacationhoursremain\" editable=\"false\" visible=\"true\" /></controls><permissions><activities><start>false</start><pause>false</pause><stop>false</stop></activities><backpermission>False</backpermission><selectablepersons>False</selectablepersons><selectableSender>False</selectableSender><selectableStarter>False</selectableStarter><ViewProcess>False</ViewProcess><ViewFinalTillNow>False</ViewFinalTillNow><CanSendToOthers>False</CanSendToOthers><attachfile>True</attachfile></permissions></person></persons><stepvalidation><conditionfields>37,28,28</conditionfields><conditionexpression></conditionexpression></stepvalidation></step><step number=\"2\"><positions><position id=\"23\" /></positions><persons><person id=\"53\" position=\"23\"><systemfolder>2</systemfolder><controls><control fieldname=\"قسمت درخواست مرخصي\" fieldlatinname=\"request part for vacation\" fieldcontrolname=\"pnldarkhast\" editable=\"false\" visible=\"true\" /><control fieldname=\"بخش مربوط به مدير قسمت\" fieldlatinname=\"supervisor part\" fieldcontrolname=\"pnlmodir\" editable=\"true\" visible=\"true\" /><control fieldname=\"چرخه دارد\" fieldlatinname=\"is workflow\" fieldcontrolname=\"checkbox_isworkflow\" editable=\"false\" visible=\"false\" /><control fieldname=\"قسمت مربوط به کار گزيني\" fieldlatinname=\"human resource part\" fieldcontrolname=\"pnlkargozeni\" editable=\"false\" visible=\"false\" /><control fieldname=\"ساعت باقي مانده\" fieldlatinname=\"remain hours\" fieldcontrolname=\"pnlvacationhoursremain\" editable=\"false\" visible=\"false\" /></controls><permissions><activities><start>true</start><pause>true</pause><stop>true</stop></activities><backpermission>True</backpermission><selectablepersons>False</selectablepersons><selectableSender>False</selectableSender><selectableStarter>True</selectableStarter><ViewProcess>False</ViewProcess><ViewFinalTillNow>False</ViewFinalTillNow><CanSendToOthers>False</CanSendToOthers><attachfile>False</attachfile></permissions></person></persons><stepvalidation><conditionfields>53</conditionfields><conditionexpression></conditionexpression></stepvalidation></step><finish number=\"0\"><positions><position id=\"7\" /><position id=\"3\" /></positions><persons><person id=\"30\" position=\"7\"><systemfolder>2</systemfolder><controls /><permissions><activities><start>false</start><pause>false</pause><stop>false</stop></activities><backpermission>False</backpermission><selectablepersons>False</selectablepersons><selectableSender>False</selectableSender><selectableStarter>False</selectableStarter><ViewProcess>False</ViewProcess><ViewFinalTillNow>False</ViewFinalTillNow><CanSendToOthers>False</CanSendToOthers><attachfile>False</attachfile></permissions></person><person id=\"56\" position=\"3\"><systemfolder>2</systemfolder><controls /><permissions><activities><start>false</start><pause>false</pause><stop>false</stop></activities><backpermission>False</backpermission><selectablepersons>False</selectablepersons><selectableSender>False</selectableSender><selectableStarter>False</selectableStarter><ViewProcess>False</ViewProcess><ViewFinalTillNow>False</ViewFinalTillNow><CanSendToOthers>False</CanSendToOthers><attachfile>False</attachfile></permissions></person></persons><message>Request_Denied</message></finish><enduser><systemfolder>0</systemfolder></enduser></steps> </root> ");
ds.ReadXml(rr);<br />
StringBuilder sb = new StringBuilder();<br />
ds.WriteXml(new StringWriter(sb));<br />
i get error while importing it to datagridview.<br />
Cannot add a column named 'controls': a nested table with the same name already belongs to this DataTable.<br />
<root> <steps><step number="1"><positions><position id="21" /><position id="19" /></positions><persons><person id="37" position="21"><systemfolder>4</systemfolder><controls><control fieldname="قسمت درخواست مرخصي" fieldlatinname="request part for vacation" fieldcontrolname="pnldarkhast" editable="true" visible="true" /><control fieldname="بخش مربوط به مدير قسمت" fieldlatinname="supervisor part" fieldcontrolname="pnlmodir" editable="false" visible="false" /><control fieldname="چرخه دارد" fieldlatinname="is workflow" fieldcontrolname="checkbox_isworkflow" editable="false" visible="false" /><control fieldname="قسمت مربوط به کار گزيني" fieldlatinname="human resource part" fieldcontrolname="pnlkargozeni" editable="false" visible="false" /><control fieldname="ساعت باقي مانده" fieldlatinname="remain hours" fieldcontrolname="pnlvacationhoursremain" editable="false" visible="true" /></controls><permissions><activities><start>false</start><pause>false</pause><stop>false</stop></activities><backpermission>False</backpermission><selectablepersons>False</selectablepersons><selectableSender>False</selectableSender><selectableStarter>False</selectableStarter><ViewProcess>False</ViewProcess><ViewFinalTillNow>False</ViewFinalTillNow><CanSendToOthers>False</CanSendToOthers><attachfile>True</attachfile></permissions></person><person id="28" position="19"><systemfolder>4</systemfolder><controls><control fieldname="قسمت درخواست مرخصي" fieldlatinname="request part for vacation" fieldcontrolname="pnldarkhast" editable="true" visible="true" /><control fieldname="بخش مربوط به مدير قسمت" fieldlatinname="supervisor part" fieldcontrolname="pnlmodir" editable="false" visible="false" /><control fieldname="چرخه دارد" fieldlatinname="is workflow" fieldcontrolname="checkbox_isworkflow" editable="false" visible="false" /><control fieldname="قسمت مربوط به کار گزيني" fieldlatinname="human resource part" fieldcontrolname="pnlkargozeni" editable="false" visible="false" /><control fieldname="ساعت باقي مانده" fieldlatinname="remain hours" fieldcontrolname="pnlvacationhoursremain" editable="false" visible="true" /></controls><permissions><activities><start>false</start><pause>false</pause><stop>false</stop></activities><backpermission>False</backpermission><selectablepersons>False</selectablepersons><selectableSender>False</selectableSender><selectableStarter>False</selectableStarter><ViewProcess>False</ViewProcess><ViewFinalTillNow>False</ViewFinalTillNow><CanSendToOthers>False</CanSendToOthers><attachfile>True</attachfile></permissions></person></persons><stepvalidation><conditionfields>37,28,28</conditionfields><conditionexpression></conditionexpression></stepvalidation></step><step number="2"><positions><position id="23" /></positions><persons><person id="53" position="23"><systemfolder>2</systemfolder><controls><control fieldname="قسمت درخواست مرخصي" fieldlatinname="request part for vacation" fieldcontrolname="pnldarkhast" editable="false" visible="true" /><control fieldname="بخش مربوط به مدير قسمت" fieldlatinname="supervisor part" fieldcontrolname="pnlmodir" editable="true" visible="true" /><control fieldname="چرخه دارد" fieldlatinname="is workflow" fieldcontrolname="checkbox_isworkflow" editable="false" visible="false" /><control fieldname="قسمت مربوط به کار گزيني" fieldlatinname="human resource part" fieldcontrolname="pnlkargozeni" editable="false" visible="false" /><control fieldname="ساعت باقي مانده" fieldlatinname="remain hours" fieldcontrolname="pnlvacationhoursremain" editable="false" visible="false" /></controls><permissions><activities><start>true</start><pause>true</pause><stop>true</stop></activities><backpermission>True</backpermission><selectablepersons>False</selectablepersons><selectableSender>False</selectableSender><selectableStarter>True</selectableStarter><ViewProcess>False</ViewProcess><ViewFinalTillNow>False</ViewFinalTillNow><CanSendToOthers>False</CanSendToOthers><attachfile>False</attachfile></permissions></person></persons><stepvalidation><conditionfields>53</conditionfields><conditionexpression></conditionexpression></stepvalidation></step><finish number="0"><positions><position id="7" /><position id="3" /></positions><persons><person id="30" position="7"><systemfolder>2</systemfolder><controls /><permissions><activities><start>false</start><pause>false</pause><stop>false</stop></activities><backpermission>False</backpermission><selectablepersons>False</selectablepersons><selectableSender>False</selectableSender><selectableStarter>False</selectableStarter><ViewProcess>False</ViewProcess><ViewFinalTillNow>False</ViewFinalTillNow><CanSendToOthers>False</CanSendToOthers><attachfile>False</attachfile></permissions></person><person id="56" position="3"><systemfolder>2</systemfolder><controls /><permissions><activities><start>false</start><pause>false</pause><stop>false</stop></activities><backpermission>False</backpermission><selectablepersons>False</selectablepersons><selectableSender>False</selectableSender><selectableStarter>False</selectableStarter><ViewProcess>False</ViewProcess><ViewFinalTillNow>False</ViewFinalTillNow><CanSendToOthers>False</CanSendToOthers><attachfile>False</attachfile></permissions></person></persons><message>Request_Denied</message></finish><enduser><systemfolder>0</systemfolder></enduser></steps> </root>
|
|
|
|
|
Please adjust the formatting and clarify your question.
Veni, vidi, caecus
|
|
|
|
|
How are you connecting your data to the datagridview?
Every day, thousands of innocent plants are killed by vegetarians.
Help end the violence EAT BACON
|
|
|
|
|
|
I would read the XML into the dataset and then use the dataset to display the data in the grid
i.e.
DatagridviewName.DataSource = ds.Tables[0];
Every day, thousands of innocent plants are killed by vegetarians.
Help end the violence EAT BACON
|
|
|
|
|
have you used my xml??
thanks inn advanced!
|
|
|
|
|
Do you have a schema for this XML?
Every day, thousands of innocent plants are killed by vegetarians.
Help end the violence EAT BACON
|
|
|
|