|
In real life, I was a chemist - and although the several suggestions for an enum are a direct way to create your listing, I would look towards future use (which is likely to come, some day), where you'd maybe want to add the atomic no., valence, atomic wt., phase at STP, full name (viz-a-viz, symbol) and so on.
It's very little additional effort to prepare for these potentialities: create a data class, each element receiving its own instance. Declare a data member for each additional feature as you need them.
As for the container, the Dictionary is a good option for your original task, conversion of formulas into molecular weights. Note that using the data class allows you to store your initialization data for the table in a wide variety of formats: from hard coded to database.
An additional consideration: getting familiar with generalized solutions to a problem (extensible data class) will make good practice for solving general problems in the future. After all, how different is the periodic table data from a music library or phone book?
"The difference between genius and stupidity is that genius has its limits." - Albert Einstein | "As far as we know, our computer has never had an undetected error." - Weisert | "If you are searching for perfection in others, then you seek dissappointment. If you are searching for perfection in yourself, then you seek failure." - Balboos HaGadol Mar 2010 |
|
|
|
|
|
Thank you.
So...basicaly, design a class in itself for the structure with its pwn data members, static members etc, instead of simply adding an enum to a different class, or the main program?
Thank you
Steve
|
|
|
|
|
Hi all,
Basic problem: ListView is limited to 256x256 pixel images - but I'll be showing thumbnails of pictures that are fairly large and there's no chance these would show any real information in only 256 pixels so I think I need to make my own visual control that allows for larger thumbnails.
I'm thinking this new viewer would have to be based on a PictureBox and it's easy enough to make these dynamically, assign the thumbs to them, handle any mousemove and click events and so on - but I'm struggling with the problem of scrolling the collection: I really can't work out how to do it! What I'd *like* is to have something along the lines of the ListView (I'd only need or want 'LargeImages' naturally) so that the control dynamically provides scroll bars as required.
It looks to me like I need to borrow from the ListView - or inherit its behaviour to some degree - but I've never needed to look at scroll-management at this level and really don't know where to start (oh, for the source for ListView...
I'd be grateful for any pointers that might help me understand the problems I need to address!
Thanks!
|
|
|
|
|
Here are two hints for you:
1.
if you put one or more large Controls (say a Panel) inside a small Panel, the small one will scroll all of it provided you set its ScrollBars properties. So you get pan functionality for free.
2.
Having a large number of PictureBoxes is a bad idea. Actually a single PictureBox isn't worth much either. It is a very poor Control. I'd rather paint the image myself onto whatever surface I have, say a Panel.
Summary: you can do all of it using just two Panels!
I suggest you perform a few simple experiments.
|
|
|
|
|
Thanks Luc! I'm forming the opinion that you don't sleep much 'cause you're replies on here are legion!
Your idea, btw, looks perfect - it's workable and solves a lot of manual work in a very neat way!
It requires me to manage rows, etc. when resizing the GUI (people will 'expect' items to consume rows 2, 3, etc. automatically) but this is no big deal. When I want to deal with panning the row(s), I'll talk to the Windows message queue and post scroll events now I have the scroll bars for 'free'
Thanks again, Sir!
Dave
p.s. PictureBox? Nah, I'll drop it: I mentioned it simply to identify I had an image & to give readers a sense of what I want to present. Naturally, I will paint to the panel: as you say, there's no need for the PictureBox in your solution (I've got to render a thumbnail anyway - what does it matter where I eventually paint it?!)
|
|
|
|
|
You're welcome.
FWIW: reading all of MSDN and replying a couple of messages is more relaxing than a night's sleep.
|
|
|
|
|
Hi guys : I try to do the same functionality, i have a list of icons (toolbar), i want to scrool it with a finger swipe over a touch screen,
how is the best way to do this over a .net in compact framework ?
Have you a sample code to do that ?
Best Regards Paolo
|
|
|
|
|
I don't know. Probably in the same way. And no, no sample code.
|
|
|
|
|
I have a short program to draw a line and rectangle with the mouse. I am new to C# and am having trouble continuing this code to draw an ellipse(perhaps bounded by rectangle).
public void OnMouseMove_Handler(Object sender, MousEventArgs e)
{ if (e.Button == MouseButtons.Left)
{ Form CurrentForm = (Form)sender;
if (SelectedShape == "Line")
ControlPaint.DrawReversibleLine (CurrentForm.PointToScreen(StartPoint),
CurrentForm.PointToScreen(EndPoint), Color.Black);
EndPoint = new Point(e.X, e.Y);
ControlPaint.DrawReversibleLine(CurrentForm.PointToScreen(EndPoint), Color.Black);
}
Then I use an "else if" to do the same for the rectangle. I just cannot seem to get this to work for an ellipse. I know that I must construct rectangle and pass to Draw Ellipse method. Just cannot get it to work.
|
|
|
|
|
Please give specifics. "Cannot get it to work" doesn't clue us in to what the problem is.
|
|
|
|
|
|
Can you show the exact code that is supposed to draw the ellipse?
|
|
|
|
|
I tried the same as rectangle which works OK.
else if (SelectedShape == "Ellipse")
{ ControlPaint.DrawReversibleFrame(CurrentForm.EllipseToScreen(SelectionEllipse), Color.Black, FrameStyle.Dashed);
SelectionEllipse.width = e.x-SelectedEllipse.x;
SelectionEllipse.height = e.y-SelectedEllipse.y;
ControlPaint.DrawReversibleFrame(CurrentForm.EllipseToScreen(SelectionEllipse), Color.Black, FrameStyle.Dashed);
private void EllipseButton_Click(object sender, EventArgs e)
{ SelectedShape = "Ellipse"; }
I am trying to draw with the mouse event; works OK for line and rectangle. I probably am missing how to send to graphics as ellipse. Just cannot find the info on MSDN or here.
Thanks
|
|
|
|
|
I think you're going about it the wrong way.
Try this code:
(this would be your form)
System.Drawing.Graphics graphics = this.CreateGraphics();
System.Drawing.Rectangle rectangle = new System.Drawing.Rectangle(
100, 100, 200, 200);
graphics.DrawEllipse(System.Drawing.Pens.Black, rectangle);
|
|
|
|
|
Thank you, I will give it a try. It appears that the coordinates eare entered by the person doing the code. I am trying to draw this with the mouse and reversible frame. But, I will try. Thanks
|
|
|
|
|
Are you trying to do a rubber-banding effect?
There are a few articles here on Code Project that describe good ways to accomplish that.
|
|
|
|
|
I tried googling "EllipseToScreen" and couldn't find it anywhere.
Where did you find that method?
|
|
|
|
|
Thanks for the info about rubberbanding; I will try to find these articles. The Ellipse to screen I tried did not work. I got this info from a book VisualC# 2005 Express edition by Aneesha Bakharia. It works great for the Line or Rectangle. I just cannot get it to work on the Ellipse. Here is what I did for the Rectangle.
public partial class Form1 : Form
{
//Create variables to store rectangle object
Rectangle SelectionRectangle = new Rectangle();
Point StartPoint = new Point();
Point EndPoint = new Point();
string SelectedShape = "Rectangle";
public void OnMouseDown_Handler(Object sender, MouseEventArgs e)
{
//mousedown can capture start coordinates and reset rectangle
SelectionRectangle.Width = 0;
SelectionRectangle.Height = 0;
SelectionRectangle.X = e.X;
SelectionRectangle.Y = e.Y;
StartPoint.X = e.X;
StartPoint.Y = e.Y;
EndPoint = StartPoint;
}
else if (SelectedShape == "Rectangle") //This is during mouse move
{
ControlPaint.DrawReversibleFrame(CurrentForm.RectangleToScreen(SelectionRectangle),
Color.Black, FrameStyle.Dashed);
SelectionRectangle.Width = e.X - SelectionRectangle.X;
SelectionRectangle.Height = e.Y - SelectionRectangle.Y;
ControlPaint.DrawReversibleFrame(CurrentForm.RectangleToScreen(SelectionRectangle),
Color.Black, FrameStyle.Dashed);
else if (SelectedShape == "Rectangle") //This is during mouse up
{
ControlPaint.DrawReversibleFrame(CurrentForm.RectangleToScreen(SelectionRectangle),
Color.Black, FrameStyle.Dashed);
g.DrawRectangle(pen, SelectionRectangle);
}
g.Dispose();
|
|
|
|
|
The code you have posted is difficult to read. If you use the proper formatting to make it more readable you may receive more help.
Look for "code block" on the toolbar above the textbox you entered you're question and use it. Also, read the forum guideleines at the top. "Ellipse" is not a very descriptive subject.
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
Sorry New to codeproject and C#. Got a couple books and self-teaching. I will review the codeproject info.
|
|
|
|
|
Hi Friend!
Are you trying to draw an ellipse like this ?
public partial class Form1 : Form
{
Rectangle SelectionRectangle = new Rectangle();
string SelectedShape = "None";
public Form1()
{
InitializeComponent();
}
private void Form1_MouseDown(object sender, MouseEventArgs e)
{
if (SelectedShape == "Ellipse")
{
SelectionRectangle.Width = 0;
SelectionRectangle.Height = 0;
SelectionRectangle.X = e.X;
SelectionRectangle.Y = e.Y;
}
}
private void Form1_MouseMove(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
SelectionRectangle.Width = e.X - SelectionRectangle.Left;
SelectionRectangle.Height = e.Y - SelectionRectangle.Top;
Invalidate();
Update();
}
}
private void Form1_MouseUp(object sender, MouseEventArgs e)
{
if (SelectedShape == "Ellipse")
{
SelectionRectangle.Width = e.X - SelectionRectangle.Left;
SelectionRectangle.Height = e.Y - SelectionRectangle.Top;
Invalidate();
Update();
}
}
private void button2_Click(object sender, EventArgs e)
{
SelectedShape = "Ellipse";
}
private void button1_Click(object sender, EventArgs e)
{
SelectedShape = "None";
}
private void Form1_Paint(object sender, PaintEventArgs e)
{
if ((SelectedShape == "Ellipse") && (SelectionRectangle != null))
{
Graphics g = e.Graphics;
g.DrawEllipse(Pens.Black, SelectionRectangle);
g.DrawRectangle(Pens.Gray, SelectionRectangle);
}
}
|
|
|
|
|
Lamrin Thank you, I will try this. I did something similar; but, with draw reversible frame. It
just kept drawing a rectangle. In your code, you refer to button 1 and 2. Are these the mouse clicks
or a button on the tool strip bar? Told you I was new to this.
|
|
|
|
|
Lamrin Thanks I tried something similar with draw reversible frame. It did not work; kept drawing a rectangle. I will try the version you supplied. When you show button 1 and 2 click; are these the mouse clicks? Prior to these click events, you show mouse down, move and up.
|
|
|
|
|
Hi Wayne Macdaid,
I think I need to give a little more explanation for my code. And I am sorry that I omitted to mention that you need to drag and drop two buttons on the form! Any way, here is a more detailed explanation of the code:
First create a 'Windows application' project (not console application) in Visual Studio (VS).
By default, you will have one blank form open in VS. Drag and drop two buttons. Name the first button "None" and the second "Ellipse". Now clicking the button1 sets the variable 'SelectedShape' to "None". So the application stops drawing ellipses. When you click button2 it sets the variable 'SelectedShape' to "Ellipse" and the application now starts drawing the ellipse whenever you start clicking and dragging on the form. In short, these buttons switch 'On' and switch 'Off' the drawing of the ellipse. By default, the variable 'SelectedShape' is set to 'None' at the time of initialisation of the application.
Now about the events.
We want to draw an ellipse only when 'SelectedShape' is set to 'Ellipse'. So when you press the mouse button down (see code Form1_MouseDown event)we check whether 'SelectedShape' has been set to "Ellipse". If so we store the X,Y co-ordinates from the mouse event as the top-left co-ords. of the SelectionRectangle.
After you press the left mouse button down, you have to drag the mouse to draw the ellipse ( and also, if needed, the bounding rectangle i.e. SelectionRectangle). When you move the mouse over the form, Windows generates 'MouseMove' events. So we have to handle this event when the mouse moves. We do this inside 'Form1_MouseMove'. Here, we first check if the left mouse button is still down. (Otherwise, the mouse button has been released). If so, we calculate the width and height of the SelectionRectangle using the the top-left co-ords. of the SelectionRectangle and the current mouse pointer position. Now one important point to note here is that we want to show a 'rubberbanding' effect in drawing the rectangle and ellipse. This will actually be done by the 'Form1_Paint' event. Since any changes in the size of the SelectionRectangle should be reflected on the Form immediately. So we first 'Invalidate' the form and then call 'Update' method. This will cause the 'Form1_Paint' event to be executed immediately.
Inside the 'Form1_Paint' event, we first check to see if the 'SelectedShape' is "Ellipse". If it is so, we proceed to draw the rectangle and the ellipse.
When we finish drawing the ellipse and releases the mouse button, we just store the re-calculated width and height of the 'SelectionRectangle' and again call 'Invalidate' and 'Update' and exit.
One important thing to note while doing graphics under Windows is that, Windows re-draws the contents of a window every now and then. i.e. when it is minimized, maximized, moved, is overlapped by any window or part of it etc. When redrawing it clears everything on its surface first. So what has been drawn outside of the window's 'OnPaint' event gets erased. So all drawing should be done inside the 'Paint' event. This is one major error committed by beginners to graphics under Windows.
Hope this clears your doubts.
Happy coding,
Lamrin
|
|
|
|
|
Thank you Lamrin - I will give this a try.
|
|
|
|
|