Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Graphics in C# versus Graphics in Java

Graphics in C# versus Graphics in Java

Scheduled Pinned Locked Moved C#
graphicshelpcsharpjavaquestion
2 Posts 2 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    dbstudio
    wrote on last edited by
    #1

    Hello guys and girls I'm recently started on C# but as I know abit programming (Coming from Java) it should be easy to do this, but as I have experienced from Microsoft its never easy on customizing or subclassing their components (I've tried in Win32/C Old school, but thats many years ago) The question is: I want to draw a dropshadowborder on a panel and/or take it further to draw all components with a dropshadow when they are added to the panel I started on subclassing Panel to override OnPaint, but as I cannot do the following code (atleast not yet) in C# I would like to have an explanation if you guys/girls are up for it or willing to help me out so I learn abit more this day // Sample code working in Java

    @Override
    public void paint(Graphics g) {
    if (shadow == null) {
    BufferedImage buffer = new BufferedImage(getWidth(),
    getHeight(),
    BufferedImage.TYPE_INT_ARGB);
    Graphics2D g2 = buffer.createGraphics();
    super.paint(g2);
    shadow = factory.createShadow(buffer);
    g2.dispose();
    g.drawImage(shadow, distance_x, distance_y, null);
    g.drawImage(buffer, 0, 0, null);
    } else if (isVisible()) {
    g.drawImage(shadow, distance_x, distance_y, null);
    super.paint(g);
    }
    }

    // End of sample snippet My snippet in C#: //Snippet from C#

    protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
    {
    Image buffer = new Bitmap(Width, Height);
    Graphics g2 = Graphics.FromImage(buffer); // Here I want to take a "snapshot" of the panel it self or the components added to the panel but cant quite see where I shall steal the "image" I know atm this is "white"
    g2.FillRectangle(new SolidBrush(Color.Black), new Rectangle(5, 5, Width, Height));
    e.Graphics.DrawImage(buffer, 0, 0);
    }

    I know the code convertion isnt exact the same but it was to point out my problem I hope you can see what I want to do, and I hope someone is willing to spend some minutes answering me with some theory. My Best Regards and Wishes David Bundgaard

    C 1 Reply Last reply
    0
    • D dbstudio

      Hello guys and girls I'm recently started on C# but as I know abit programming (Coming from Java) it should be easy to do this, but as I have experienced from Microsoft its never easy on customizing or subclassing their components (I've tried in Win32/C Old school, but thats many years ago) The question is: I want to draw a dropshadowborder on a panel and/or take it further to draw all components with a dropshadow when they are added to the panel I started on subclassing Panel to override OnPaint, but as I cannot do the following code (atleast not yet) in C# I would like to have an explanation if you guys/girls are up for it or willing to help me out so I learn abit more this day // Sample code working in Java

      @Override
      public void paint(Graphics g) {
      if (shadow == null) {
      BufferedImage buffer = new BufferedImage(getWidth(),
      getHeight(),
      BufferedImage.TYPE_INT_ARGB);
      Graphics2D g2 = buffer.createGraphics();
      super.paint(g2);
      shadow = factory.createShadow(buffer);
      g2.dispose();
      g.drawImage(shadow, distance_x, distance_y, null);
      g.drawImage(buffer, 0, 0, null);
      } else if (isVisible()) {
      g.drawImage(shadow, distance_x, distance_y, null);
      super.paint(g);
      }
      }

      // End of sample snippet My snippet in C#: //Snippet from C#

      protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
      {
      Image buffer = new Bitmap(Width, Height);
      Graphics g2 = Graphics.FromImage(buffer); // Here I want to take a "snapshot" of the panel it self or the components added to the panel but cant quite see where I shall steal the "image" I know atm this is "white"
      g2.FillRectangle(new SolidBrush(Color.Black), new Rectangle(5, 5, Width, Height));
      e.Graphics.DrawImage(buffer, 0, 0);
      }

      I know the code convertion isnt exact the same but it was to point out my problem I hope you can see what I want to do, and I hope someone is willing to spend some minutes answering me with some theory. My Best Regards and Wishes David Bundgaard

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      The control has a method that causes it to render itself to a bitmap. It's called DrawToBitmap. Use that to create a copy of your control in a bitmap, then you can manipulate it.

      Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups