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. Graphics
  4. WPF: Rounded rects on only certain corners?

WPF: Rounded rects on only certain corners?

Scheduled Pinned Locked Moved Graphics
csharpwpfquestion
4 Posts 2 Posters 2 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.
  • C Offline
    C Offline
    chaiguy1337
    wrote on last edited by
    #1

    Hey all. I posted this here because I don't see a specific WPF forum. I'm curious if anyone else has wanted to or figured out a way to draw rectangles with only certain of the four corners rounded (for e.g. the bottom corners only). I bet I could sit down and work out a way to do this, but I'm new to WPF so wanted to see if it's been done before. Thanks, Logan

    {o,o}.oO( Did somebody say MouseDown? ) |)””’) -”-”-

    J 1 Reply Last reply
    0
    • C chaiguy1337

      Hey all. I posted this here because I don't see a specific WPF forum. I'm curious if anyone else has wanted to or figured out a way to draw rectangles with only certain of the four corners rounded (for e.g. the bottom corners only). I bet I could sit down and work out a way to do this, but I'm new to WPF so wanted to see if it's been done before. Thanks, Logan

      {o,o}.oO( Did somebody say MouseDown? ) |)””’) -”-”-

      J Offline
      J Offline
      Jared Bienz MSFT
      wrote on last edited by
      #2

      You can do it, but you have to get a bit tricky. The window border itself can’t be changed, but you can make a borderless window with a shape inside of it that does what you want. You then have to enable dragging the ‘window’ based on dragging its contents, but it’s not a big deal. Start by setting the following styles on the window: WindowStyle="None" Background="{x:Null}" AllowsTransparency="True" ResizeMode="NoResize" Inside this window you’ll need to place a Border object. Inside the Border you can place whatever you want. Now on the Border set its CornerRadius to something like CornerRadius="0,22,0,22" and set your fill and stroke as desired. Finally, you’ll need to be able to reposition the window regardless of where the user clicks. Fortunately WPF lets you capture events both on the way down (Preview) and on the way back up through the element stack (Element). So to complete your project, in your window class add the following code: protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e) { base.OnMouseLeftButtonDown(e); DragMove(); } And that’s it. You can use this trick for creating windows of literally any shape. Even animation should be supported, though I haven’t tried it. Disclaimer: I’ve only tried this on Vista. I think it SHOULD work on XP, but the Desktop Window Manager in Vista may make a difference.

      My posts may include factual data, educated guesses, personal opinion and dry humor. They should not be treated as an official Microsoft statement.
      Sites of Interest: MSDN Events | US ISV Team Blog

      J 1 Reply Last reply
      0
      • J Jared Bienz MSFT

        You can do it, but you have to get a bit tricky. The window border itself can’t be changed, but you can make a borderless window with a shape inside of it that does what you want. You then have to enable dragging the ‘window’ based on dragging its contents, but it’s not a big deal. Start by setting the following styles on the window: WindowStyle="None" Background="{x:Null}" AllowsTransparency="True" ResizeMode="NoResize" Inside this window you’ll need to place a Border object. Inside the Border you can place whatever you want. Now on the Border set its CornerRadius to something like CornerRadius="0,22,0,22" and set your fill and stroke as desired. Finally, you’ll need to be able to reposition the window regardless of where the user clicks. Fortunately WPF lets you capture events both on the way down (Preview) and on the way back up through the element stack (Element). So to complete your project, in your window class add the following code: protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e) { base.OnMouseLeftButtonDown(e); DragMove(); } And that’s it. You can use this trick for creating windows of literally any shape. Even animation should be supported, though I haven’t tried it. Disclaimer: I’ve only tried this on Vista. I think it SHOULD work on XP, but the Desktop Window Manager in Vista may make a difference.

        My posts may include factual data, educated guesses, personal opinion and dry humor. They should not be treated as an official Microsoft statement.
        Sites of Interest: MSDN Events | US ISV Team Blog

        J Offline
        J Offline
        Jared Bienz MSFT
        wrote on last edited by
        #3

        Ha ha ha. I just realized you only needed the rounded rectangle and I took you all the way to the rounded window. Oh well, all you needed was the CornerRadius bit. And I think you even wrote an article already? Well, good job!

        My posts may include factual data, educated guesses, personal opinion and dry humor. They should not be treated as an official Microsoft statement.
        Sites of Interest: MSDN Events | US ISV Team Blog

        C 1 Reply Last reply
        0
        • J Jared Bienz MSFT

          Ha ha ha. I just realized you only needed the rounded rectangle and I took you all the way to the rounded window. Oh well, all you needed was the CornerRadius bit. And I think you even wrote an article already? Well, good job!

          My posts may include factual data, educated guesses, personal opinion and dry humor. They should not be treated as an official Microsoft statement.
          Sites of Interest: MSDN Events | US ISV Team Blog

          C Offline
          C Offline
          chaiguy1337
          wrote on last edited by
          #4

          Haha, yes I wrote an article for a Shape-derived class called PartiallyRoundedRectangle before I found out about Border's ability to do essentially the same thing. I found out about that through the article though, so it wasn't a complete waste of time. ;) Thanks for the in-depth instructions for making rounded borderless windows even if it's not exactly what I was asking for. ;) Logan

          {o,o}.oO( Did somebody say MouseDown? ) |)””’) -”-”-

          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