|
hi
i need a control that display my image maps and panning and zooming it in my control.
i was create a userControl named ImageMap, and add a panel to it and set Doc to Fill and wrote this code to get result :
public partial class ImageMap : UserControl<br />
{ <br />
Bitmap bitmap; <br />
BufferedGraphicsContext currentContext;<br />
BufferedGraphics myBuffer; <br />
PointF viewPortCenter;<br />
float Zoom = 1.0f;<br />
<br />
bool draging = false;<br />
Point lastMouse;<br />
public static Rectangle rec;<br />
<br />
<br />
public ImageMap()<br />
{<br />
InitializeComponent();<br />
currentContext = BufferedGraphicsManager.Current;<br />
setup(false);<br />
rec = this.panel1.DisplayRectangle;<br />
} <br />
<br />
private void setup(bool resetViewport)<br />
{ <br />
if (myBuffer != null)<br />
myBuffer.Dispose();<br />
myBuffer = currentContext.Allocate(this.panel1.CreateGraphics(), this.panel1.DisplayRectangle);<br />
if (bitmap != null)<br />
{<br />
if (resetViewport)<br />
SetViewPort(new RectangleF(0, 0, bitmap.Width, bitmap.Height)); <br />
} <br />
this.panel1.Focus();<br />
this.panel1.Invalidate();<br />
} <br />
<br />
private void SetViewPort(RectangleF worldCords)<br />
{ <br />
if (worldCords.Height > worldCords.Width)<br />
{<br />
this.Zoom = worldCords.Width / bitmap.Width;<br />
}<br />
else<br />
this.Zoom = worldCords.Height / bitmap.Height;<br />
<br />
viewPortCenter = new PointF(worldCords.X +(worldCords.Width / 2.0f), worldCords.Y + (worldCords.Height / 2.0f));<br />
<br />
} <br />
<br />
private void PaintImage()<br />
{<br />
if (bitmap != null)<br />
{<br />
float widthZoomed = panel1.Width / Zoom;<br />
float heigthZoomed = panel1.Height / Zoom;<br />
<br />
if (widthZoomed > 30000.0f)<br />
{<br />
Zoom = panel1.Width / 30000.0f;<br />
widthZoomed = 30000.0f;<br />
}<br />
if (heigthZoomed > 30000.0f)<br />
{<br />
Zoom = panel1.Height / 30000.0f;<br />
heigthZoomed = 30000.0f;<br />
}<br />
<br />
if (widthZoomed < 2.0f)<br />
{<br />
Zoom = panel1.Width / 2.0f;<br />
widthZoomed = 2.0f;<br />
}<br />
if (heigthZoomed < 2.0f)<br />
{<br />
Zoom = panel1.Height / 2.0f;<br />
heigthZoomed = 2.0f;<br />
}<br />
<br />
float wz2 = widthZoomed / 2.0f;<br />
float hz2 = heigthZoomed / 2.0f;<br />
Rectangle drawRect = new Rectangle(<br />
(int)(viewPortCenter.X - wz2),<br />
(int)(viewPortCenter.Y - hz2),<br />
(int)(widthZoomed),<br />
(int)(heigthZoomed));<br />
<br />
<br />
myBuffer.Graphics.Clear(Color.White);
<br />
myBuffer.Graphics.DrawImage(bitmap, this.panel1.DisplayRectangle, drawRect, GraphicsUnit.Pixel);<br />
myBuffer.Render(this.panel1.CreateGraphics());<br />
} <br />
}<br />
<br />
protected override void OnBackgroundImageChanged(EventArgs e)<br />
{<br />
bitmap = (Bitmap)this.BackgroundImage;<br />
setup(true);<br />
base.OnBackgroundImageChanged(e);<br />
}<br />
<br />
protected override void OnResize(EventArgs e)<br />
{<br />
setup(false);<br />
base.OnResize(e);<br />
}<br />
<br />
private void panel1_Paint(object sender, PaintEventArgs e)<br />
{ <br />
PaintImage();<br />
}<br />
<br />
private void panel1_MouseWheel(object sender, System.Windows.Forms.MouseEventArgs e)<br />
{<br />
Zoom += Zoom * (e.Delta / 1200.0f);
if (e.Delta > 0)
viewPortCenter = new PointF(viewPortCenter.X + ((e.X - (panel1.Width / 2)) /(2* Zoom)), viewPortCenter.Y + ((e.Y - (panel1.Height/2)) / (2*Zoom))); <br />
this.panel1.Invalidate(); <br />
}<br />
<br />
private void panel1_MouseDown(object sender, MouseEventArgs e)<br />
{<br />
if (e.Button == MouseButtons.Left)<br />
draging = true;<br />
}<br />
<br />
private void panel1_MouseMove(object sender, MouseEventArgs e)<br />
{<br />
if (draging)<br />
{<br />
viewPortCenter = new PointF(viewPortCenter.X + ((lastMouse.X - e.X)/Zoom), viewPortCenter.Y + ((lastMouse.Y- e.Y)/Zoom)); <br />
panel1.Invalidate(); <br />
}<br />
lastMouse = e.Location;<br />
}<br />
<br />
private void panel1_MouseUp(object sender, MouseEventArgs e)<br />
{<br />
if (e.Button == MouseButtons.Left)<br />
draging = false;<br />
} <br />
}
but in runTime, when i panning image in my control, it has a flicker and very bad result, for solve this problem, in top of above code, i define a new class that derived from Panel and wrote this code :
public class overRidePanel : Panel<br />
{<br />
protected override void OnPaintBackground(PaintEventArgs pevent) <br />
{<br />
<br />
}<br />
}
then modify my panel to instanciate from new overRidePanel class, as u can see in above code, i was override OnPaintBackground event only, then run my app, it gave me best result and remove flicker when i panning and zomming my images in app, but when my app run, the ImageMap does not have a any image to display it, and my control in runTime does not display white color correctly(it show back of the my app and not good for me), i want when i start app, it is white color before selecting image, but how to do ?
thanks
|
|
|
|
|
Hello,
I've been trying for while now to upload a picture and get it to be displayed in an Image control. I still can't get the code right. I used
FileUpload1.PostedFile.SaveAs(filepath);
Image1.ImageURL = filepath;
after performing the necessary checks. The ASP.NET debugger says the path format is not supported. I need help.
Thanks.
Obinna from Nigeria.
PS. I'm using VS 2005.
//obinnaaj Eof
|
|
|
|
|
You need to store it within your web app, then your imageURL needs to be a URL to the file, not a path on the file system. Server.MapPath is how you convert them,
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
In .Net, Text box control is in square shape. I would like to change the shape of the control to Circle from square shape. Is it possible to customize the shape of Textbox control as circle?
Thanks in advance.
|
|
|
|
|
By overriding OnPaint method
|
|
|
|
|
Not really, no. The textbox in windows sucks because it paints itself often outside it's paint event. It can be done, but it's hard work. Why not just draw a circle of white around the edges of a textbox with no border ?
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
|
*grin* for any other control it would probably be right. It still is, excepting that you need to handle a bunch of other events and force repaints, and you'll never get rid of the flicker.
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Thanks
Meanwhile, was the reply for the earlier thread (disable copy paste) correct?
|
|
|
|
|
Yes, it looked like it to me. I'd have to try it to see if it worked, but that's what I had in mind.
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Thanks for your reply. But how to draw circle in windows form design? Please guide me.
|
|
|
|
|
The FillEllipse method of the Graphics class. You'd create a control with a textbox and a circle drawn around it.
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Hello,
how to disbale copy paste from and to textbox programatically
|
|
|
|
|
hey
you might be able to "catch" the event of(ctrl + c) and (ctrl + v) and not handle it...
that might do the trick
Hav fun
Harvey Saayman - South Africa
Junior Developer
.Net, C#, SQL
think BIG and kick ASS
you.suck = (you.passion != Programming)
|
|
|
|
|
You may be able to do this by catching the keystrokes and rejecting them. I don't think there's a paste event. You would probably need to reset the clipboard after a CTRL-Insert or CTRL-C, b/c it's probably already done.
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Like this:
private void textBox1_KeyDown(object sender, KeyEventArgs e) {<br />
if(e.Control && e.KeyCode == Keys.C) {<br />
e.SuppressKeyPress = true;<br />
}<br />
else if(e.Control && e.KeyCode == Keys.V) {<br />
e.SuppressKeyPress = true;<br />
}<br />
}
|
|
|
|
|
private void textBox1_KeyDown(object sender, KeyEventArgs e) {
if(e.Control && e.KeyCode == Keys.C) {
e.SuppressKeyPress = true;
}
else if(e.Control && e.KeyCode == Keys.V) {
e.SuppressKeyPress = true;
}
}
this is good, but i do't want to this code paste in all control.
i want this code type only one time
|
|
|
|
|
prakash_adysoft wrote: i do't want to this code paste in all control.
i want this code type only one time
Do you mean you want this code to execute only once?
If yes then just unbind it using
this.textBox1.KeyDown -= new KeyEventHandler(this.textBox1_KeyDown);
|
|
|
|
|
Aside from the fact he probably shouldn't have just posted up this code as an instant solution (requiring the OP to do nothing for himself), the code only needs to be written once, you can bind one event to multiple controls.
He who makes a beast out of himself gets rid of the pain of being a man
|
|
|
|
|
What if the user copies or pasties using context menu of the textbox?
Giorgi Dalakishvili
#region signature
my articles
#endregion
|
|
|
|
|
Just reinitialize the context menu of the textbox during form load without any items in it.
|
|
|
|
|
I actually found a bug, where you can still get the context menu even when you do that.
If i remember right, to get the context menu to STILL appear, you right-click the text box and hold the button down - move you mouse off of the text box - and then release the button. Then the normal menu appears
My current favourite word is: Bacon!
-SK Genius
Game Programming articles start - here[ ^]-
|
|
|
|
|
Thanks for find.
How about handling this in WndProc method then?
|
|
|
|
|
hello,
I have an application that allow me to create many Forms.
When i open many forms i get this error : Error creating windows handle.
After i check for this kind of error, there is many suggestion to minimize the number of controls(handles) because each process do suppport a specified number of controls.
but my forms contain a user controls and more thing that i can't remove.
Do someone have any idea fr this kind of error.
Best regards,
dghdfghdfghdfghdgh
|
|
|
|
|
Hard to make sense of this. How many windows do you have open ?
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|