7 Replies - 9206 Views - Last Post: 16 December 2008 - 06:49 AM Rate Topic: -----

#1 sachintha81  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 14-December 08

Loading Multiple Images to a Picture Box

Posted 14 December 2008 - 06:07 PM

Hello,
Actually I'm not sure if a Picture Box is the right control for my need, but I'm just guessing it is. I'm new to C#, so haven't got much of an idea. I'm using MS Visual C# 2005.

Here is my problem.

I read data from a file which contains text lines seperated by a return. Then according to the data lines, I need a verticle bar (deciding what this control is upto me, and I'm guessing it is a Picture Box) be filled with different colors.

For example let's say this is the text file.

A
B
C
A



Then, in the C# Form, on whatever that control I need four color lines be displayed according to the text. So, if we assign colors as follows:
A - Red
B - Yellow
C - Green

Then the color lines should be displayed like
Red
Yellow
Green
Red

I think you get the drift.
Please note that there could be any number of text lines in the text file, but the control height I use need to be remained the same. So, according to the number of lines in the text file, height of each color strip in the control should differ.

Please help me with this.
Thanks in advance.

P.S. I've attached a image here so you'd get a better idea of what I need.

Attached image(s)

  • Attached Image


Is This A Good Question/Topic? 0
  • +

Replies To: Loading Multiple Images to a Picture Box

#2 fremgenc  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 119
  • Joined: 15-November 07

Re: Loading Multiple Images to a Picture Box

Posted 14 December 2008 - 06:17 PM

How far are you with this?
Have you read in the file?

Please elaborate a little on where exactly you are in this.

Also,

Dream.In.Code has a policy by which we prefer to see a good faith effort on your part before providing source code for homework assignments. Please post the code you have written in an effort to resolve the problem, and our members would be happy to provide some guidance. Be sure to include a description of any errors you are encountering as well.

Please post like this: Posted Image
Was This Post Helpful? 0
  • +
  • -

#3 eclipsed4utoo  Icon User is offline

  • Not Your Ordinary Programmer
  • member icon

Reputation: 1526
  • View blog
  • Posts: 5,961
  • Joined: 21-March 08

Re: Loading Multiple Images to a Picture Box

Posted 15 December 2008 - 07:57 AM

I would probably look into using a RichTextBox. It allows you to set the color of the lines.
Was This Post Helpful? 0
  • +
  • -

#4 sachintha81  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 14-December 08

Re: Loading Multiple Images to a Picture Box

Posted 15 December 2008 - 05:41 PM

View Postfremgenc, on 14 Dec, 2008 - 05:17 PM, said:

How far are you with this?
Have you read in the file?

Please elaborate a little on where exactly you are in this.

Also,

Dream.In.Code has a policy by which we prefer to see a good faith effort on your part before providing source code for homework assignments. Please post the code you have written in an effort to resolve the problem, and our members would be happy to provide some guidance. Be sure to include a description of any errors you are encountering as well.

Please post like this: Posted Image



Yes reading the file thing is done. Actually, someone else does it and my part is to display this sort of 'indicator'.
But reading part is OK, and for the moment I just use test data.

After posting this yesterday, I have done something like this and achieved some success.

private void panel1_Paint(object sender, PaintEventArgs e)
		{
			using (Graphics g = e.Graphics)
			{
				int iLineHeight = panel1.Height / iRows;

				for (int i = 0; i < iRows; ++i)
				{
					int y = i * iLineHeight;
					
					Point point1 = new Point(0, y);
					Point point2 = new Point(this.Width, y);
					
					g.DrawLine(new Pen(Color.Orange, iLineHeight), point1, point2);
				}
			}
		}



I used a Panel Control, and it's Paint property.
iRows is the number of lines in the text file.
Then I calculate the line height depending on the number of lines.
Then, I paint a line using that - determine the point 1 and 2.
I haven't done differentiating color according to the contents in text file, but it should be no problem.
But now the problem is, there could be like 10000 lines in this file and I can only show as many lines as the height of the Panel Control.

View Posteclipsed4utoo, on 15 Dec, 2008 - 06:57 AM, said:

I would probably look into using a RichTextBox. It allows you to set the color of the lines.


But can that be used to display like 10000 lines?
Thanks for your ideas mate. Help greatly appreciated.
Was This Post Helpful? 0
  • +
  • -

#5 eclipsed4utoo  Icon User is offline

  • Not Your Ordinary Programmer
  • member icon

Reputation: 1526
  • View blog
  • Posts: 5,961
  • Joined: 21-March 08

Re: Loading Multiple Images to a Picture Box

Posted 15 December 2008 - 07:43 PM

View Postsachintha81, on 15 Dec, 2008 - 07:41 PM, said:

View Posteclipsed4utoo, on 15 Dec, 2008 - 06:57 AM, said:

I would probably look into using a RichTextBox. It allows you to set the color of the lines.


But can that be used to display like 10000 lines?
Thanks for your ideas mate. Help greatly appreciated.


I don't see why not. Though I do not know the maximum number of lines the RichTextBox can hold. I thought I posted code on how I used a RichTextBox. Maybe I didn't.
Was This Post Helpful? 0
  • +
  • -

#6 fremgenc  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 119
  • Joined: 15-November 07

Re: Loading Multiple Images to a Picture Box

Posted 15 December 2008 - 08:46 PM

try

//calculate vertical increment
float VInterval = panel1.Height / iRows;

for(int i =0;i<iRows.Count;i++)
	   g.FillRectangle(Brushes.Blue,0.0,VInterval*i,(float)panel1.Width,VInterval);



Was This Post Helpful? 0
  • +
  • -

#7 sachintha81  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 14-December 08

Re: Loading Multiple Images to a Picture Box

Posted 16 December 2008 - 03:19 AM

View Postfremgenc, on 15 Dec, 2008 - 07:46 PM, said:

try

//calculate vertical increment
float VInterval = panel1.Height / iRows;

for(int i =0;i<iRows.Count;i++)
	   g.FillRectangle(Brushes.Blue,0.0,VInterval*i,(float)panel1.Width,VInterval);





I got it to work somewhat.
But there is also something else I need help with.

In the program, there is also a DataGridView. Actually, the data read from the file is first put into it and then this color strip is created.

Now, when the user press F5, I need the data grid view to refresh and also the color strip according to the new values.

I can get the DGV to refresh, but not PanelControl.

private void dataGridView1_KeyDown(object sender, KeyEventArgs e)
		{
			switch (e.KeyCode)
			{
				case Keys.F5:
					Form1_Load(sender, e);
					panel1_Paint(this.panel1, e);
					break;
			}
		}



Here, form1_Load event - where I add data to the DGV - occurs without any problems.
But Paint event doesnt. It gives the following two errors.

エラー	1	'LogViewerTEST.Form1.panel1_Paint(object, System.Windows.Forms.PaintEventArgs)' に最も適しているオーバーロード メソッドには無効な引数がいくつか含まれています。	C:\My Work\HONSHA\BSLogViewer Program\LogViewerTEST\LogViewerTEST\Form1.cs	66	21	LogViewerTEST


Translation : Invalid arguments in 'LogViewerTEST.Form1.panel1_Paint(object, System.Windows.Forms.PaintEventArgs)'

エラー	2	引数 '2': 'System.Windows.Forms.KeyEventArgs' から 'System.Windows.Forms.PaintEventArgs' に変換できません。	C:\My Work\HONSHA\BSLogViewer Program\LogViewerTEST\LogViewerTEST\Form1.cs	66	47	LogViewerTEST


Translation : The parameter number 2 cannot be changed from System.Windows.Forms.KeyEventArgs to System.Windows.Forms.PaintEventArgs.

Any ideas?
Was This Post Helpful? 0
  • +
  • -

#8 eclipsed4utoo  Icon User is offline

  • Not Your Ordinary Programmer
  • member icon

Reputation: 1526
  • View blog
  • Posts: 5,961
  • Joined: 21-March 08

Re: Loading Multiple Images to a Picture Box

Posted 16 December 2008 - 06:49 AM

in your code, "e" is a type of KeyEventArgs. The "panel1_Paint" method accepts an object and a PaintEventArgs parameters. This is why you are getting the error.

You could relate this to you trying to send a string as the parameter when the method only accepts an integer as a parameter. You get a type mis-match.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1