|
You draw on the bitmap instead of the panel. Once it is on the bitmap you draw the bitmap to the panel.
The OnPaint method is called with the panel is invalidated or otherwise needs to be repainted. This is why you need to draw the bitmap in the OnPaint.
And one thing I didn't explain before is that you probably want to create your own class derived from Panel so that you can override the OnPaint method (otherwise you will be creating an OnPaint method in the wrong place)
If you are using these functions I would also recommend Charles Petzold's book on programming Windows with .NET.
|
|
|
|
|
Well I have a bunch of books at home... I just always skipped over the graphics part of it lol. I will go back and read those now that I see where I would use them... I got it to work.. this is what I did:
private Bitmap bmp;
MouseMove:
private void panelSig_MouseMove(object sender, MouseEventArgs e)
{
if (shouldPaint)
{
Graphics graphic = Graphics.FromImage(bmp);
Cursor.Clip = new Rectangle(this.PointToScreen(panelSig.Location), panelSig.Size);
graphic.DrawLine(pen, lastPoint.X, lastPoint.Y, e.X, e.Y);
graphic.Dispose();
lastPoint.X = e.X;
lastPoint.Y = e.Y;
panelSig.Invalidate();
Cursor.Clip = new Rectangle(0, 0, 0, 0);
}
}
OnPaint (draw the BMP on the panel)
private void panelSig_Paint(object sender, PaintEventArgs e)
{
Graphics graphic = e.Graphics;
graphic.DrawImage(bmp, 0, 0, bmp.Width, bmp.Height);
}
private void panelSig_MouseDown(object sender, MouseEventArgs e)
{
shouldPaint = true;
lastPoint.X = e.X;
lastPoint.Y = e.Y;
}
private void panelSig_MouseUp(object sender, MouseEventArgs e)
{
shouldPaint = false;
}
Seems to work great so far...
|
|
|
|
|
I want to bind an in-memory data class to a DataGridView using the DataSource member. I have read several ways of doing this and have implemented and tried several but once I set the DataSource, I then lose the ability to sort.
I want to display my data class inside of a grid. I can use a List (List < MyDataClass >, for example) which works but I lose sorting. I can get sorting back, but I have to create my row like this
<br />
object[] row = {MyDataClass.FirstName, MyDataClass.LastName};<br />
which then removes the binding to the actual objects.
I've now been trying to use DataSets and DataTables, but I still lose my binding. And the columns are not automatically generated from the exposed properties, like when I use a List collection.
My next step is to create a class implementing the IBindingList interface. Will this be what I want? Any help or advice is greatly appreciated. Thanks.
Oh, another wrench in the idea is that I want to flatten out the object. So my object may contain other objects which I want to also display in the table as part of the same row. I was thinking there was a way to bind a specific grid column to an object's property, but I haven't been able to find that yet.
|
|
|
|
|
When you say you lose the sorting on your List do you mean the ability to sort of the order you want loaded?
I use a BindingSource as the DataSource for the DGV, but the data (from a SQL select) is loaded into the List in the order I want them displayed. So the sort is done before loasing the list. Any subsequent sorting is done by the user via the DGV.
List<clsProduct> lProducts = oProd.GetRecordList(-1);<br />
dgData.DataSource = lProducts;
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
By losing the sort, I mean I can no longer sort when clicking on the column. This is just the nature of using a List or array as your datasource as they don't know how to sort per column. Also, when I say this is in-memory data, what I really mean is this is not connected to a database.
I now have things working by deriving from IBindingList and implementing the sort routines as well as adding a Comparer, but it took me awhile. I tried How To Allow To Sort By Multiple Columns in Custom Data Binding which would not compile. It is based on an article from MSDN. So I fixed up the code to be like the MSDN article and, though it would compile, I still could not sort on my columns.
I ended up having to use a sample in the MSDN Library for an IBindingList interface. But even THAT example does not show how to sort. So I took the necessary bits I needed from Implementing a strongly typed collection with sort/filter/GetChanges features and finally got things working.
|
|
|
|
|
That sounds like an article to me.
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.”
|
|
|
|
|
You are probably correct. I have now spent more time with things and have things working pretty well. I think I have the solution I was looking for.
|
|
|
|
|
Hi All
I have three forms in my application Form1 (main form), Form2 and Form3.
Is there any easy way to call method or event which is on Form1 from Form3.In my application there is a method in form1 which is showing records on ListView of Form1 from a file.
In Form3 I am adding two records in the file and after that form3 and form2(which is intermediatery form) both are closed and Form1 becomes the active form.Now I want to call a method or event so that two records are added to the ListView without calling Page load.
I can not declare that method/event as public due to security reason.
protected internal is okay.
Searching on the net confused me and i did not understood anything.
Please guide.
Thanks
Regards
The SK
|
|
|
|
|
Sandeep Kalra wrote: Is there any easy way to call method or event which is on Form1 from Form3
Yes. It is essentially the same as passing a value (a property is just syntactic sugar for a get and set method). Passing Values between Forms with C# and VB.NET examples[^]
Sandeep Kalra wrote: Page load.
Page? Is this a web application?
Sandeep Kalra wrote: I can not declare that method/event as public due to security reason.
protected internal is okay.
The accessor levels of methods has nothing to do with security. If you want security you might want to look into areas such as CAS (Code Access Security). If someone wants to to call your method then they can do so quite easily using reflection. So, making something private, protected or internal has zero security associated with it.
Sandeep Kalra wrote: Searching on the net confused me and i did not understood anything.
Then this may turn into a conversation.
|
|
|
|
|
1.Yes. It is essentially the same as passing a value (a property is just syntactic sugar for a get and set method). Passing Values between Forms with C# and VB.NET examples[^]
I have studied above topic but I do not have to pass values.
2. Page? Is this a web application?
Its a windows based application.
3.The accessor levels of methods has nothing to do with security. If you want security you might want to look into areas such as CAS (Code Access Security). If someone wants to to call your method then they can do so quite easily using reflection. So, making something private, protected or internal has zero security associated with it.
I did not knew about that.So Is this mean that I have to use CAS to improve security of my application.
Please guide
Thanks
Regards
THE SK
|
|
|
|
|
Morning fellow coders;
I need to come up with a networkable sign in sign out board. Can somebody tell me if there are any samples to look at or give me the big picture of what I would need to do.
i.e.
Would this have to be ASP.net or can I do this with windows forms?
thanks in advance for any information
rafone
Statistics are like bikini's...
What they reveal is astonishing ...
But what they hide is vital ...
|
|
|
|
|
It can be done with either forms or asp. The difference being with forms, every sign in point needs a copy or a mapping to a copy of the executable, with asp you need a browser and the address of the page.
Which way you go really depends on what you're more comfortable with and how you expect it to be used. Do you need update notifications if someone hasn't signed in or out, do you only need current status or a tracking log of historical times.
The most simplistic version is to simply install an IM client on each persons machine if you just need to know if they're in the office. If you actually want to track their in/out times, then you'll have to make something. A simple database with two tables, employee name/id's and a recent activity table with ID/date/time/last activity, would handle the data. Then you just need to make an interface to update/read the tables as needed.
The true man wants two things: danger and play. For that reason he wants woman, as the most dangerous plaything.
|
|
|
|
|
Please bare with me I only started learning c# a few days back.
Anyway I am creating a split function (by line not file size) and thus far I have got it to create do the necessary math & create its directory. However I have a problem in my loop in which the error: Cannot write to a closed TextWriter. I just cant seem to solve this problem and need some help!
<br />
private void btnSplit_Click(object sender, EventArgs e)<br />
{<br />
string inputFile = this.txtFileToImport.Text;
FileStream fs = new FileStream(inputFile, FileMode.Open, FileAccess.Read);<br />
int numberOfFiles = (int)this.numericUpDown1.Value;<br />
int numberOfRows = (int)this.dataGridView_preView.RowCount - 1;<br />
decimal rowsPerFile = numberOfRows / numberOfFiles;<br />
int sizeOfEachFile = (int)Math.Ceiling((double)rowsPerFile);<br />
lblPray.Text = " Rows: " + sizeOfEachFile.ToString();<br />
<br />
string OutputFolder = inputFile + "_Batches";<br />
if (Directory.Exists(inputFile) == false)<br />
<br />
{<br />
Directory.CreateDirectory(OutputFolder);<br />
}<br />
<br />
System.IO.StreamReader reader = new System.IO.StreamReader(inputFile);<br />
string strHeader = reader.ReadLine();<br />
<br />
int FileIndex = 0;<br />
<br />
do<br />
{<br />
<br />
string PiecePath = OutputFolder + "\\" + Path.GetFileNameWithoutExtension(inputFile) + "_" + FileIndex + Path.GetExtension(inputFile);<br />
StreamWriter Writer = new StreamWriter(PiecePath, false);<br />
Writer.AutoFlush = false;<br />
Writer.WriteLine(strHeader);<br />
<br />
for (int i = 1; i <= sizeOfEachFile; i++)<br />
{<br />
<br />
string s = reader.ReadLine();<br />
if (s != null & _IsAbort == false)<br />
{<br />
Writer.WriteLine(s);<br />
}<br />
else<br />
{<br />
Writer.Flush();<br />
Writer.Close();<br />
}<br />
}<br />
<br />
Writer.Flush();<br />
Writer.Close();<br />
}<br />
while (true);<br />
} <br />
}<br />
}<br />
Ive probably been looking straight at the problem and just been sitting here far to long to realise... either that or its all wrong! Any help would be much appreciated.
Cheers
|
|
|
|
|
Hi,
Before helping with your problem, let me recommend something to you born out of years of experience:
Don't write your own CSV parser![^]
Seriously, hell is awaiting you if you're trying to parse a CSV file by hand.
Your first thought is, "I need to handle commas inside of quotes."
Your next thought will be, "Oh, crap, I need to handle quotes inside of quotes. Escaped quotes. Double quotes. Single quotes..."
Instead of rolling your own, use an existing library that has done the work for you, such as the free FileHelper[^] library.
Religiously blogging on the intarwebs since the early 21st century: Kineti L'Tziyon
Judah Himango
|
|
|
|
|
It seems you are trying to flush the file after closing it.
Also, please make your code more readable by using the <pre> tag and correct indentation.
|
|
|
|
|
I'm not sure where your problem lies, but
do
{
} while (true); is an infinate loop - never a good idea, plus I can't see anywhere you attempt to break out of it.
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
|
|
|
|
|
Something like this ought to do it (assuming you are only splitting by lines and not parsing each line):
do
{
string PiecePath = OutputFolder + "\\" + Path.GetFileNameWithoutExtension(inputFile) + "_" + FileIndex + Path.GetExtension(inputFile);
using (StreamWriter Writer = new StreamWriter(PiecePath, false))
{
Writer.AutoFlush = false;
Writer.WriteLine(strHeader);
int linesOut = 0;
while( (linesOut < sizeOfEachFile) && ((s = reader.ReadLine()) != null) )
{
linesOut++;
Writer.WriteLine(s);
}
}
FileIndex++;
} while (s != null);
There might be the odd misplaced ( or ) - just done off the top of my head.
Have a look at your calculation for sizeOfEachFile - why two a decimal and a double? What do you get when you divide an int by an int and assign it to a decimal?
Regards
David R
|
|
|
|
|
Thanks you very much for all your help its now working properly and I have also taking all your advice under consideration and changed my code accordingly!
Cheers
|
|
|
|
|
You're welcome.
Regards
David R
|
|
|
|
|
Hello,
I've got an easy on for you all.
Since I chose to have input of QueryTime possibly be a decimal (ex ".5"), I have kept it a decimal.
However, Timer.Interval is an int and I need to convert a decimal to an int.
public void StartTimer(decimal QueryTime)
{<br />
int shizz = Decimal.ToInt32(QueryTime);
int wtf = (Decimal.ToInt32(QueryTime) * 60) * 1000;
<br />
QueryTimer.Interval = ((int)QueryTime * 60)* 1000;<br />
QueryTimer.Enabled = true;<br />
<br />
}
Event when QueryTime = 0.5, both shizz and wtf are 0.
Does anyone know how to properly convert a decimal to an integer?
Thanks,
Matt
|
|
|
|
|
A decimal will not fit in an integer so you have to decide in code how you want it to fit.
Have a look at the Math class in particular its Round method with MidPointRoundingMode
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
|
|
|
|
|
Hello!
Thanks for your response.
I am giving the users the option to set the interval of the timer. I had specified "minutes." Instead, I can specify "seconds" and keep it int throughout.
However, I'll take a look at this for future reference.
Thanks!
Matt Brown
|
|
|
|
|
In that case, maybe a TimeSpan would be more appropriate?
I used some thing similar in my ApplicationIdle component article[^]
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
|
|
|
|
|
Other idea:
int non_wtf = Decimal.ToInt32(QueryTime * 60 * 1000);
Btw, why a decimal? Why not, say, a float or double? Almost everything that uses non-integral values uses either floats or doubles, decimal is rare (and slow, and only meant for when the numbers are for human interaction since they expect 4 instead of 3.99999999 for example)
|
|
|
|
|
Thanks for the input.
I'd like to have users be able to input values of 10-.01 as a string.
I then would like to convert this string to a value.
I would then multiply this value by 60, then 1000.
Then I would like to take this value and change it into an integer.
What value should I be converting the string to perform the calculations?
Thanks,
Matt
|
|
|
|