|
Did you post information on Tournaments anywhere?? I'd be interested to see what you did on this.
Thanks..
ed
~"Watch your thoughts; they become your words. Watch your words they become your actions.
Watch your actions; they become your habits. Watch your habits; they become your character.
Watch your character; it becomes your destiny."
-Frank Outlaw.
|
|
|
|
|
Hi Guys,
How can I implement a separator in ComboBox, such that objects of two different classes can be easily distinguised. Does it require any coding or just simple designing tactics? Please Help.....
Your help will be appreciated.....
Rajdeep.NET!
modified on Thursday, April 2, 2009 3:42 PM
|
|
|
|
|
AFAIK you can't without quite a bit of work.
You'd need to set the DrawMode to one of the OwnerDrawn modes, and handle the DrawItem event yourself to detect whatever you use as a separator and draw what you require. Making it non selectable is going to be another challenge!
I know you're a beginner in C#, this may be a little adventurous IMO until you've got to grips fully with the fundementals.
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)
|
|
|
|
|
Oh my! There seems to be huge task to be accomplished . I think I have to learn how to draw graphics on Windows Forms in order to achieve this. Anyways, thanx Davey. u r very helpful!
|
|
|
|
|
I am a little confused by this.. I get it to draw the lines on the panel, but when I try to save it to a file it is blank?
Here is my panels MouseMove:
private void panelSig_MouseMove(object sender, MouseEventArgs e)
{
if (shouldPaint)
{
Graphics graphic = panelSig.CreateGraphics();
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(new Rectangle(0, 0, panelSig.Width, panelSig.Height));
Cursor.Clip = new Rectangle(0, 0, 0, 0);
}
}
Here is the MouseDown and MouseUp:
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;
}
But when I try to save it to a file it doesnt work?? I'm confused... I realy want to save it in a SQL database, but I figured I should get it to save to a file first to see.. It saves.... just the panel, not the actual lines I drew.
Here is how I am saving it:
Bitmap TestBMP = new Bitmap(panelSig.Width, panelSig.Height);
FileStream fs = new FileStream(saveFile.FileName, FileMode.Create, FileAccess.Write);
panelSig.DrawToBitmap(TestBMP, new Rectangle(0, 0, panelSig.Width, panelSig.Height));
TestBMP.Save(fs, ImageFormat.Png);
fs.Close();
|
|
|
|
|
You will also find that if you drag your window off the side of the screen then drag it back on again you will have lost the lines you have drawn too.
This is because what you draw is not stored anywhere. It is simply drawn on the surface. If the panel is invalidated the OnPaint method is called and it is redrawn, losing what ever you drew on it.
If you need to store the information you need to draw to a bitmap, then draw the bitmap onto the panel. When you come to save the information to a file (or database) you have the bitmap already.
And, by the way, your panel will have to re-draw the bitmap in the OnPaint method.
|
|
|
|
|
Well what is being drew on the panel is a signature.
So I still need each line put... how exactly would I save that to a bitmap or just do it with the OnPaint method.
|
|
|
|
|
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
|
|
|
|