|
There are two approaches that spring to mind, but before I suggest them would you please confirm the impression I got from your first post.
You want to do this when the user presses the mouse button in one picturebox (MouseDown), moves the mouse (without releasing the button) to another picturebox and then releases the button (MouseUp).
Please confirm that I have understood this correctly.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Hi, Henry,
Thank you for your quick reply! YES! That's what I mean, I really need your help. Thank you so much.
I won't never ever give up!!
|
|
|
|
|
Option 1 (probably the easiest)
Declare two class level PictureBox variables, one for the first (mousedown) and one for the second (mouseup).
In the MouseDown and MouseUp event handlers, identify the PictureBox where the event occurred and assign it to the correct variable.
Add a call to ColorChanged() at the end of the MouseUp handler
I'll do the MouseDown , from that you can work out how to do MouseUp
private PictureBox firstBox = null;
private PictureBox secondBox = null;
private void OnMouseDown(object sender, MouseEventArgs e)
{
PictureBox pb = sender as PictureBox;
if (pb != null)
{
firstBox = pb;
}
else
{
firstBox = null;
}
StartTime = getTimeAt(e.X, e.Y);
Updating();
}
after making the changes to MouseUp your ColorChanged() should firstly check if firstBox or secondBox is null, and if so return (nothing to do if you don't have two PictureBoxes ). then it is simply a matter of firstBox.BackColor = Color.Blue; (same for secondBox), or however you want to set the color.
I won't give you the second idea unless you don't think this will work as it is far more complicated.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Heh,
Great! Thank you, Henry! I will try this option now. After I do this, I will post what I got here then, pls keep an eye on this post. Thanks a lot.
Liang
I won't never ever give up!!
|
|
|
|
|
Hi,Henry,
I am sorry to say this. But it seems we had some misunstanding, I guess I need you option two. In my project, I have more than two PictureBoxes, and I want to make it to have the function that user press button on one PictureBox without releasing(MouseDown), and move to another one, then release it(MouseUp). But there might be also PictureBoxes between these two PictureBoxes. Here I cut a sample picture of part of my design, I hope you can give me some help.
Oh, NO! I can't insert a picture into this post. Damn.
Henry, if you still confuse what I am saying cuz my english is so sucks. Could you pls reply me by e-mail: sunly917@gmail.com. I can send the picture to your mailbox.
Thank you and BR!
Liang
|
|
|
|
|
I'm afraid that Option 2 would not help in the circumstances as you now describe them, since it was simply a more complicated way to do the same as Option 1.
The only way to do what you want, in the way that you want to do it, that I can think of, is to slightly modify the code I have already given you. Basically what you need to do is to handle the MouseMove event of the control hosting your PictureBox es. Each time the event fires it should iterate over all the PictureBox es and test if the cursor location is within the PB pb1.Bounds.Contains(e.Location) , or similar and if so, add it to a list and break out of the iteration. Therefore instead of the firstBox and secondBox you will need a collection, I would suggest List<PictureBox> . Don't forget to Clear() it on MouseDown and to add the first and second boxes to it. then in your ChangeColour iterate over the collection and do your recolouring stuff on each PB in it.
The problem with doing things in the way that you want is that if the user moves the mouse very, very quickly, one of the PBs could get missed.
[Edit]
An alternative to my suggested MouseMove approach, would be to calculate a path from the MouseDown point to the MouseUp point and then test for a PB at intervals along that path. The interval would depend on the size of the PBs.
[/Edit]
[Edit * 2]
You could of course combine the two approaches. Have a class level GraphicsPath instance, on MouseDown create a new GraphicsPath e.g. myClassLevelGP = new GraphicsPath() . Make a note of the MouseDown point. myClassLevelStartPoint = e.Location; . Then in the MouseMove handler.
myClassLevelGP.AddLine(myClassLevelStartPoint, e.Location);
myClassLevelStartPoint = e.Location;
Then in the MouseUp handler put the same two lines of code.
What you will end up with is a GraphicsPath containing lots and lots of tiny lines, tracking the path the mouse has taken.
Then in the ColorChange method you will have to iterate over the points contained in the path (look up GraphicsPath.PathPoints and GraphicsPath.PathData for suitability), and for each point iterate over the PBs and pb.Bounds.Contains(point) as mentioned above.
That's a lot of points * a lot of PBs and could take some time, not to mention the problems from fast mousing mentioned above.
You might be better off by rethinking your approach. For example, allowing users to Ctrl-Click on the PBs they want to recolour adding them to the list. They would of course have to click a button or something to trigger the recolouring and any click without Ctrl should clear the list.
[/Edit * 2]
I hope that at least part of my ramblings is of use.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Hi, Henry,
Thank you so much. Though I still don't think what you told me to do is the way in which I can handle my project, your talented thoughts have refreshed my brain a lot. As you said, I may really need to rethink how I could do this project. Anyway, what I expect to do is a time period selector, you know, similar to GOOGLE calendar, but not for recording daily events. I only want to make a similar WINSFORM application that users can catch a period of time and return the StartTime and EndTime, later on, maybe I would do that collection recording each period to a ListBox each time user trigger the Mouse Events. I have collected information referred to this for a long time, and there is an article here in CodeProject named DayView Calendar, but that is quite different, and since I am not so good at GDI, it's also difficult for me to understand how it was modeled.
But, really, thank you for your kind help. Hope we will always keep in touch.
Br!
Sincerely Liang
|
|
|
|
|
string connection2=ConfigurationManager .AppSettings ["conn"];
OleDbConnection con2 = new OleDbConnection(connection2);
OleDbDataAdapter da_detail = new OleDbDataAdapter();
DataSet ds_detail = new DataSet();
con2.Open();
string query = "select * from DOCTORFORM where NAME = '" + DropDownList1.SelectedItem.Value + "' ";
OleDbCommand pay_cmd2 = new OleDbCommand(query,con2);
da_detail.SelectCommand = pay_cmd2;
da_detail.Fill(ds_detail ,"details");
DataTable detail_dt=ds_detail .Tables ["details"];
GridView1.DataSource = detail_dt;
GridView1.DataBind();
this is how am getting the values into gridview.is there any other way without doing databind.
|
|
|
|
|
Why do you think your approach is not good ?
Vuyiswa Maseko,
Few companies that installed computers to reduce the employment of clerks have realized their expectations.... They now need more and more expensive clerks even though they call them "Developers" or "Programmers."
C#/VB.NET/ASP.NET/SQL7/2000/2005/2008
http://www.vuyiswamaseko.somee.com
vuyiswa@its.co.za
http://www.itsabacus.co.za/itsabacus/
|
|
|
|
|
it works fine for one time binding.but if i want to append to datas to the exinting ones.like adding more rows of data every a button is clicked.it doesnt work.can u give some tips on that
|
|
|
|
|
If you want to be able to add new Records on the Gridview it can be Done this Way
http://www.dotnetfunda.com/articles/article18.aspx[^]
in Windows we do it like this
Coding an N-Tier Application in C# Without Any Wizard: Part II[^]
Hope this will help you
Vuyiswa Maseko,
Few companies that installed computers to reduce the employment of clerks have realized their expectations.... They now need more and more expensive clerks even though they call them "Developers" or "Programmers."
C#/VB.NET/ASP.NET/SQL7/2000/2005/2008
http://www.vuyiswamaseko.com
vuyiswa@its.co.za
http://www.itsabacus.co.za/itsabacus/
|
|
|
|
|
want to add new values to datatable rows on each button_click event..i want it in such a way that the new data gets added to the next row,instead of overwriting the first...Below is the code which i wrote
Button_Click event()
{OleDbDataAdapter da_pay = new OleDbDataAdapter();
DataSet ds_pay = new DataSet();
con2.Open();
da_pay.SelectCommand = pay_cmd2;
da_pay.Fill(ds_pay ,"details");
pay_dt=ds_pay .Tables ["details"];
pay_dt.Rows.Add();
con2.Close();}
But for every button click event the first row hets overwritten
|
|
|
|
|
|
could you explain more what is happening there??? where is the new data comming from is it a new row from the data base that the old table had gotten its values???what do you expect from pay_dt.Rows.Add(); to do??
try to create data columns same fields as the datatable then a datarow assign the values of the new row you want to add to the created datarow , then add the new datarow to the old dataTable or try the function DataTable.Merger(x) where it merges two dataTables.
|
|
|
|
|
I think i am missing out the basic concepts of data table..I selected values from the data source and stored it in a data set in the table details..A datatable was created in the same dataset and when it was connected to the gridview the values where displaying(eventhough i dint specified the column).I thought then if i give pay_dt(which is my data table).rows.add() then new rows eill get added to the datatable and values will also gets added.values are getting added..But it is overwriting the first
modified on Thursday, August 27, 2009 6:16 AM
|
|
|
|
|
Well first the values appeared becuase in the grid there is a prop name autogenerateColumns.
try to fill the new dataTable with the new data and then databind.
Tell me if this worked?? or there is something you need to be explained more
|
|
|
|
|
I have this application that in very brief, shows up an image from time to time...
Now, you know that if you press PrintScreen whilst a video is running, the image derived does not show the screen (if Hardware Acceleration is turned on).
I was wondering if I could achieve this in C# (without going into great lengths) - to make the image non-apparent on PrintScreen...
Or if I should use a completely different method? I had in mind of tracking the Clipboard but that would take me to great lengths and can be easily circumvented.
|
|
|
|
|
what do you want to capture ?
I just tried Google Earth with DirectX9 Mode, and using PrintScreen..-> it's working, no problem.
|
|
|
|
|
What I want is NOT to capture.. I want to make the system so that the image will not be captured when a screenshot is taken... However implementing a lock upon the PrintScreen key is not the ideal way... What I had in mind, is implementing it similar to how it works when a video is played on a PC with Hardware Acceleration on - the image is 'translucent' or something, so that it does not show up on the screenshot...
|
|
|
|
|
HI,
I have managed code. I have namespace and set the COMVisibleAttribute to TRUE. But still I am not able to access the namespace of C# projects in a ATL projects. Any suggestion.?
|
|
|
|
|
Hi
This is from Chandrakanth.
Actually myproblem is....
I want to display images in the body of the Email. It is possible ?
if it is possible means please give me some Tips on that.
If any reference....please send me that
Thanks and Regards
Chandrakanth
|
|
|
|
|
|
See here.
Life is a stage and we are all actors!
|
|
|
|
|
please tell me what is better to learn language .Net or java
|
|
|
|
|