Click here to Skip to main content
15,916,398 members
Home / Discussions / C#
   

C#

 
QuestionHow to include visio diagrams in C#.net application Pin
ysunil_7414-May-08 1:33
ysunil_7414-May-08 1:33 
AnswerRe: How to include visio diagrams in C#.net application Pin
Gareth H14-May-08 1:37
Gareth H14-May-08 1:37 
AnswerRe: How to include visio diagrams in C#.net application Pin
Simon P Stevens14-May-08 1:55
Simon P Stevens14-May-08 1:55 
QuestionHow can i obtain a textbox in my webbrowser and pass the text a windows form? Pin
solbyte14-May-08 1:19
solbyte14-May-08 1:19 
AnswerRe: How can i obtain a textbox in my webbrowser and pass the text a windows form? Pin
Christian Graus14-May-08 1:37
protectorChristian Graus14-May-08 1:37 
QuestionCrystal Report Pin
mehrdadc4814-May-08 0:40
mehrdadc4814-May-08 0:40 
AnswerRe: Crystal Report Pin
ChandraRam14-May-08 1:20
ChandraRam14-May-08 1:20 
QuestionOnPaintBackground Problem. Pin
hdv21214-May-08 0:21
hdv21214-May-08 0:21 
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 />
           //Find smallest screen extent and zoom to that<br />
            if (worldCords.Height > worldCords.Width)<br />
            {<br />
                //Use With as limiting factor<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 />
                //Do checks the reason 30,000 is used is because much over this will cause DrawImage to crash<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 />
                //we stop at 2 because at this point you have almost zoomed into a single pixel<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 />
                //this.toolStripStatusLabel1.Text = "DrawRect = " + drawRect.ToString();<br />
<br />
                myBuffer.Graphics.Clear(Color.White); //Clear the Back buffer<br />
<br />
                //Draw the image, Write image to back buffer, and render back buffer<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); //the 1200.0f is any-number it just seem to work well so i use it.<br />
            if (e.Delta > 0) //I prefer to use the targe zoom when zooming in only, remove "if" to have it apply to zoom in and out<br />
                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
QuestionUploading picture to server and display it in an Image control Pin
Dextter14-May-08 0:18
Dextter14-May-08 0:18 
AnswerRe: Uploading picture to server and display it in an Image control Pin
Christian Graus14-May-08 0:24
protectorChristian Graus14-May-08 0:24 
QuestionHow to customize .Net Textbox control Pin
NarVish13-May-08 23:45
NarVish13-May-08 23:45 
AnswerRe: How to customize .Net Textbox control Pin
dan!sh 13-May-08 23:53
professional dan!sh 13-May-08 23:53 
AnswerRe: How to customize .Net Textbox control Pin
Christian Graus13-May-08 23:58
protectorChristian Graus13-May-08 23:58 
GeneralRe: How to customize .Net Textbox control Pin
dan!sh 14-May-08 0:05
professional dan!sh 14-May-08 0:05 
GeneralRe: How to customize .Net Textbox control Pin
Christian Graus14-May-08 0:08
protectorChristian Graus14-May-08 0:08 
GeneralRe: How to customize .Net Textbox control Pin
dan!sh 14-May-08 0:11
professional dan!sh 14-May-08 0:11 
GeneralRe: How to customize .Net Textbox control Pin
Christian Graus14-May-08 0:22
protectorChristian Graus14-May-08 0:22 
GeneralRe: How to customize .Net Textbox control Pin
NarVish14-May-08 0:16
NarVish14-May-08 0:16 
GeneralRe: How to customize .Net Textbox control Pin
Christian Graus14-May-08 0:22
protectorChristian Graus14-May-08 0:22 
QuestionDisable copy paste in textbox Pin
D i x y13-May-08 23:08
D i x y13-May-08 23:08 
AnswerRe: Disable copy paste in textbox Pin
Harvey Saayman13-May-08 23:17
Harvey Saayman13-May-08 23:17 
AnswerRe: Disable copy paste in textbox Pin
Christian Graus13-May-08 23:17
protectorChristian Graus13-May-08 23:17 
GeneralRe: Disable copy paste in textbox Pin
dan!sh 13-May-08 23:43
professional dan!sh 13-May-08 23:43 
GeneralRe: Disable copy paste in textbox Pin
Bhim Prakash Singh14-May-08 0:10
Bhim Prakash Singh14-May-08 0:10 
GeneralRe: Disable copy paste in textbox Pin
dan!sh 14-May-08 0:17
professional dan!sh 14-May-08 0:17 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.