Results 1 to 3 of 3

Thread: Pic in Circle

  1. #1
    .NET Framework
    .NET 4.5
    Join Date
    Jul 2018
    Posts
    2
    Rep Power
    0

    Pic in Circle

    My next step in this code for me is to allow the user to move the pic from within the bounds of the circle

    I would like the code to drive a mouse click and hold to move it

    Then I want to have zoom functionality

    Here is what I have so far...

    using System;
    using System.Drawing;
    using System.Drawing.Drawing2D;
    using System.Windows.Forms;

    namespace Sphere_Map
    {
    public partial class Form1 : Form
    {
    public Graphics gfx;

    int radius = 300;
    int y = 350;
    int x = 350;

    public Form1()
    {
    InitializeComponent();
    gfx= this.CreateGraphics();
    }

    private void button1_Click(object sender, EventArgs e)
    {
    Bitmap tmp = new Bitmap(2 * radius, 2 * radius);
    Graphics g = Graphics.FromImage(tmp);
    g.TranslateTransform(tmp.Width / 2, tmp.Height / 2);
    GraphicsPath path = new GraphicsPath();
    path.AddEllipse(0 - radius, 0 - radius, 2 * radius, 2 * radius);
    Region region = new Region(path);
    g.SetClip(region, CombineMode.Replace);
    Bitmap bmp = new Bitmap("C://C# Graphics/Earth.jpg");
    g.DrawImage(bmp, new Rectangle(-radius, -radius, 2 * radius, 2 * radius), new Rectangle(x - radius, y - radius, 2 * radius, 2 * radius), GraphicsUnit.Pixel);
    tmp.Save("c://C# Graphics/US Boundary Map2.jpg");
    gfx.DrawImage(Bitmap.FromFile("c://C# Graphics/US Boundary Map2.jpg"),new Point(100,100));

    }

    private void btnExit_Click(object sender, EventArgs e)
    {
    if (System.Windows.Forms.Application.MessageLoop)
    {
    // WinForms app
    System.Windows.Forms.Application.Exit();
    }
    else
    {
    // Console app
    System.Environment.Exit(1);
    }
    }
    }
    }


    Thank you for the assistance

  2. #2
    .NET Framework
    .NET 4.5
    Join Date
    Apr 2011
    Posts
    1,865
    Rep Power
    145
    Firstly, please don't post your code as HTML. Notice that all indenting has been lost, making reading it more difficult. Post your code as plain text inside appropriate formatting tags, i.e.

    [xcode=c#]your code here[/xcode]

    That will take care of syntax highlighting and retain indenting.

    Secondly, NEVER call CreateGraphics. With the code you have, try minimising your form and then restoring it and you'll see that your drawing has disappeared, because all drawing is erased on a repaint. The proper approach is to store all the data describing the drawing in fields and then using those fields in the Paint event handler of the form or appropriate control. That way, your drawing will be done every time the form repaints. If the drawing needs to change, you simply change the data and then force a repaint.

    That last sentence relates directly to your request too. When the user drags the drawing, you simply force a repaint when the drag is done and, optionally, while it's in progress and the drawing will appear to move from the user's perspective. You might like to check this out for some important concepts that will help you get going.

  3. #3
    .NET Framework
    .NET 4.5
    Join Date
    Jul 2018
    Posts
    2
    Rep Power
    0

    Got it!

    Thank you. Forgive the newbie mistake.

Similar Threads

  1. Replies: 1
    Last Post: 12-20-2017, 1:06 AM
  2. Question draw circle
    By Akramselwe in forum Graphics / GDI+
    Replies: 3
    Last Post: 03-09-2016, 1:44 PM
  3. Question Research depend in Rotating circle
    By Esmat_halfa in forum Graphics / GDI+
    Replies: 3
    Last Post: 03-07-2016, 10:51 AM
  4. Mouse restriction in circle
    By Anzar in forum Windows Presentation Foundation (WPF)
    Replies: 2
    Last Post: 06-10-2015, 2:53 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •