Results 1 to 15 of 15

Thread: how to Draw rounded rectangle by vb6 GDI++?Draw a triangle

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Jan 2020
    Posts
    3,749

    how to Draw rounded rectangle by vb6 GDI++?Draw a triangle

    I want to draw various shapes, I wonder if you have the simplest example. Such as five-pointed star, trapezoid, prismatic, etc.

    Code:
    Private Sub DrawRoundRectangle(Graphics As Long, Pen As Long, X As Long, Y As Long, Width As Long, Height As Long, 
    
    Optional RoundSize As Long = 30)
    GdipDrawArcI Graphics, Pen, X, Y, RoundSize * 2, RoundSize * 2, 180, 90
    GdipDrawLineI Graphics, Pen, X + RoundSize, Y, X + Width - RoundSize, Y
    GdipDrawArcI Graphics, Pen, X + Width - RoundSize * 2, Y, RoundSize * 2, RoundSize * 2, 270, 90
    GdipDrawLineI Graphics, Pen, X + Width, Y + RoundSize, X + Width, Y + Height - RoundSize
    GdipDrawArcI Graphics, Pen, X + Width - RoundSize * 2, Y + Height - RoundSize * 2, RoundSize * 2, RoundSize * 2, 0, 90
    GdipDrawLineI Graphics, Pen, X + RoundSize, Y + Height, X + Width - RoundSize, Y + Height
    GdipDrawArcI Graphics, Pen, X, Y + Height - RoundSize * 2, RoundSize * 2, RoundSize * 2, 90, 90
    GdipDrawLineI Graphics, Pen, X, Y + RoundSize, X, Y + Height - RoundSize
    End Sub

  2. #2
    Frenzied Member
    Join Date
    Feb 2003
    Posts
    1,807

    Re: how to Draw rounded rectangle by vb6 GDI++?Draw a triangle

    Does it have to use GDI++? Perhaps it would help if you explained why need to draw these shapes.

  3. #3
    PowerPoster Arnoutdv's Avatar
    Join Date
    Oct 2013
    Posts
    5,904

    Re: how to Draw rounded rectangle by vb6 GDI++?Draw a triangle

    Why not use a polygon?

  4. #4
    PowerPoster
    Join Date
    Feb 2017
    Posts
    5,064

    Re: how to Draw rounded rectangle by vb6 GDI++?Draw a triangle

    Quote Originally Posted by xiaoyao View Post
    I want to draw various shapes, I wonder if you have the simplest example. Such as five-pointed star, trapezoid, prismatic, etc.
    Here there is code for that.

  5. #5
    Frenzied Member
    Join Date
    Dec 2012
    Posts
    1,476

    Re: how to Draw rounded rectangle by vb6 GDI++?Draw a triangle

    See if this helps:
    https://www.vbforums.com/showthread....07#post5435607

    It may be more than you need.

    J.A. Coutts

  6. #6
    Frenzied Member
    Join Date
    Feb 2003
    Posts
    1,807

    Re: how to Draw rounded rectangle by vb6 GDI++?Draw a triangle

    I once wrote a project which used the trigonometric functions sine and cosine to generate various shapes: https://github.com/PeterSwinkels/Figures. It's probably not exactly what you want but perhaps it will be of some use.

  7. #7
    Lively Member
    Join Date
    Mar 2015
    Posts
    104

    Re: how to Draw rounded rectangle by vb6 GDI++?Draw a triangle

    Here is my contribution: A Star Drawer with different styles

    You can adjust the number of points as well as the styles. Also can resize and move the circles and manually colour the inside of the star. I made this for PlanetVb but as it has gone here is my copy of it.


    Name:  stars2.jpg
Views: 731
Size:  63.9 KB

    Star Drawer Mod 2c2.zip
    Attached Images Attached Images  
    Last edited by CreativeDreamer; Apr 9th, 2021 at 09:01 AM.

  8. #8

    Thread Starter
    PowerPoster
    Join Date
    Jan 2020
    Posts
    3,749

    Re: how to Draw rounded rectangle by vb6 GDI++?Draw a triangle

    Quote Originally Posted by CreativeDreamer View Post
    Here is my contribution: A Star Drawer with different styles

    You can adjust the number of points as well as the styles. Also can resize and move the circles and manually colour the inside of the star. I made this for PlanetVb but as it has gone here is my copy of it.
    Thank you very much. Perhaps the best way to write the code for drawing various graphics is to use the latest SVG web page image format, which can be enlarged at will, and various development tools are common.

  9. #9

    Thread Starter
    PowerPoster
    Join Date
    Jan 2020
    Posts
    3,749

    Re: how to Draw rounded rectangle by vb6 GDI++?Draw a triangle

    Quote Originally Posted by Peter Swinkels View Post
    Does it have to use GDI++? Perhaps it would help if you explained why need to draw these shapes.
    My main purpose is to develop modern UI interfaces, such as adding outer borders to text boxes, glowing and other effects.
    It is also used for the development of some business processes or custom controls, which requires GDIPLUS to draw some simple shapes.
    Such as arrows, connecting line anchor points, etc. In this regard, VB.NET is very powerful, and it takes a long time to learn.

  10. #10
    PowerPoster wqweto's Avatar
    Join Date
    May 2011
    Location
    Sofia, Bulgaria
    Posts
    5,156

    Re: how to Draw rounded rectangle by vb6 GDI++?Draw a triangle

    Quote Originally Posted by xiaoyao View Post
    Thank you very much. Perhaps the best way to write the code for drawing various graphics is to use the latest SVG web page image format, which can be enlarged at will, and various development tools are common.
    This is known as Abstraction inversion anti-pattern. You are using SVG files to draw basic shapes when you'll need algorithms for drawing basic shapes to be able to implement something like a full-blown SVG parser/renderer.

    This is like using a RDBMS to sort a list of groceries or full-blown browsers to view PDFs or XMLs or click links.

    cheers,
    </wqw>

  11. #11

    Thread Starter
    PowerPoster
    Join Date
    Jan 2020
    Posts
    3,749

    Re: how to Draw rounded rectangle by vb6 GDI++?Draw a triangle

    Quote Originally Posted by wqweto View Post
    This is known as Abstraction inversion anti-pattern. You are using SVG files to draw basic shapes when you'll need algorithms for drawing basic shapes to be able to implement something like a full-blown SVG parser/renderer.

    This is like using a RDBMS to sort a list of groceries or full-blown browsers to view PDFs or XMLs or click links.

    cheers,
    </wqw>
    I used VB.NET code myself to draw a complete coordinate system, arrows, etc. with lines like a hand. With more functions, the code is very difficult to write, and the XY position will be wrong.

    Deformed. The best way is like using web design software such as DREAMWEAVER, visual development, just drag and drop controls to complete.
    The shape, etc., are just some HTM codes or XML characters in the end. There is no need to calculate the coordinates manually, and it can be scaled to any size.

    For example, when doing 4-digit verification code OCR recognition, the characters may be crooked. These have dedicated image recognition components and only need a DLL.
    There are open source components such as OPENCV for complex face recognition. In any case, it is most convenient to use the ready-made methods or components written by others.
    Just like the Cairo component, it is really convenient to manipulate the display of SVG and convert to memory PNG bytes. If it can be converted into a transparent bitmap, it will be more convenient to draw directly to other controls.

    .

    Now I still lack a code to detect the actual width and height of SVG. When converting SVG to PNG, there are many blank pixels around which need to be cut off. I want to use it later

    In commercial software, other SVG or PNG images, rounded rectangles and other shapes may be placed around the SVG image.

  12. #12

    Thread Starter
    PowerPoster
    Join Date
    Jan 2020
    Posts
    3,749

    Re: how to Draw rounded rectangle by vb6 GDI++?Draw a triangle

    Because VB6 buttons and other controls are really too old, the best way is to replace them all.
    Therefore, research on transparent components, modern UI design methods, vector graphics, animation, sound, etc. all need to be matched.
    The development of ordinary software, ERP, mes production management system also needs to be like a game engine. We need to have a variety of codes, DLLs, controls and other parts and semi-finished products to develop better-looking and more usable commercial software. At the same time, the development speed should be faster and future maintenance should be convenient.

    I just used a set of multifunctional controls developed by others: CommonControls (Replacement of the MS common controls)
    https://www.vbforums.com/showthread....mmon-controls)
    I found that for most of the controls developed by others, 80% of their source code is not understood by me, and I cannot modify or absorb them into my own. It takes a lot of time to learn to use some of the functions inside.
    I also uploaded a lot of source code and controls that I developed myself. I wonder how many people can understand? Does anyone think my code is excellent? Maybe it's bad.

  13. #13
    PowerPoster
    Join Date
    Jun 2013
    Posts
    7,253

    Re: how to Draw rounded rectangle by vb6 GDI++?Draw a triangle

    Quote Originally Posted by xiaoyao View Post
    Therefore, research on transparent components, modern UI design methods, vector graphics, animation, sound, etc. all need to be matched.
    All of your above points (and more) are accumulated (and hardened over the last decades) in the RC6-framework.

    You've just started with "modern UI stuff, including your first steps with Alpha-capable Controls" -
    whereas the above framework is the result of two decades of work in that field.
    (including 2 nearly complete GDI and GDIPlus-based versions which were thrown away in the first 5 years).

    Quote Originally Posted by xiaoyao View Post
    We need to have a variety of codes, DLLs, controls and other parts
    That's right - as a developer you need to learn to start using tools, developed by experts in their field.
    And nobody on this planet becomes an expert after only "a year or two" (after making the decision, to "dive deeper" in a certain field).

    Quote Originally Posted by xiaoyao View Post
    I just used a set of multifunctional controls developed by others: CommonControls (Replacement of the MS common controls)
    https://www.vbforums.com/showthread....mmon-controls)
    I found that for most of the controls developed by others, 80% of their source code is not understood by me, and I cannot modify or absorb them into my own.
    That's because "you're not yet there" ... lacking the required amount of gathered experience (in that specific area).

    Quote Originally Posted by xiaoyao View Post
    It takes a lot of time to learn to use some of the functions inside.
    Sure, learning how to use a new "larger lib" or "framework" properly, takes some time.

    The mistake that is often made is, to "stick to what you know, searching fast success for an isolated problem"...
    Then the usual "copy and merge" of existing (and often only half-understood) code-snippets starts -
    and after "only a few days", you got "some result" (but for only that "isolated problem").

    Well, the thing is - that the time you invested into that "fast result", was not really "that fast" (instead it was *wasted* IMO).
    If you had invested the same amount of time into learning a decently implemented library instead,
    your result would be *much* better, much more stable - and your understanding of the interface of that lib got already "a base to build on".
    And from that growing base of understanding, you can find solutions for other, similar - but *also* "not quite that similar" problems,
    much faster via "commonly usable patterns and helper-classes", the longer you work with that lib.

    See... you are currently kind of "jumping around" with your own attempts of Alpha-capable controls for about 2 weeks now.
    If you'd have invested that time into learning e.g. the RC6-libs you would have in the meantime at least
    proper "basic understanding" of its Form-engine, its Widget-engine, and the Cairo-drawing-commands.


    Quote Originally Posted by xiaoyao View Post
    I also uploaded a lot of source code and controls that I developed myself.
    I wonder how many people can understand? Does anyone think my code is excellent? Maybe it's bad.
    Most experienced users here "understand" your code - often because they wrote it in the first place ("long before you copied it").
    And yes - it is bad - really it is... (and I don't tell you that, to "rile you up").

    Everything you came up with so far:
    - was for the most part already written by others
    - is only half understood by you
    - and often based on "age old APIs" (which nobody "out there" is using anymore)

    If you'd have used a proper modern library for all that,
    your implementation-efforts would become easier, using *far* less code for a nicer looking and more stable end-result.

    IMO less "flitting around", instead applying "focus and diligence" would help you to become better.

    Well, Confucius says it better than me here:
    "The expectation of life depends on diligence - the craftsman who can do the job perfectly, has first improved the ability of his tool."
    ("對生活的期望取決於勤奮,能夠完美完成工作的技工必須首先提高工具的能力。")

    HTH

    Olaf

  14. #14
    Frenzied Member
    Join Date
    Aug 2020
    Posts
    1,447

    Re: how to Draw rounded rectangle by vb6 GDI++?Draw a triangle

    Yes, Confucius said: If a craftsman wants to do his job well, he must sharpen his tools first ("工欲善其事,必先利其器").

    Later, people further interpreted the meaning of this sentence as: "If a craftsman wants to do his job well, he must use better tools (or improve the ability of his tool)

  15. #15

    Thread Starter
    PowerPoster
    Join Date
    Jan 2020
    Posts
    3,749

    Re: how to Draw rounded rectangle by vb6 GDI++?Draw a triangle

    Quote Originally Posted by Schmidt View Post
    All of your above points (and more) are accumulated (and hardened over the last decades) in the RC6-framework.
    Well, Confucius says it better than me here:
    "The expectation of life depends on diligence - the craftsman who can do the job perfectly, has first improved the ability of his tool."
    ("對生活的期望取決於勤奮,能夠完美完成工作的技工必須首先提高工具的能力。")

    HTH

    Olaf
    You people abroad should know some of China's ancient writers.
    In fact, I have always had an ideaFor example, a control or component rc6.dll, gdi32, gdiplus, how many functions are there, listed it, and learn a hook. Just like the book for the previous database, many of us have no way to finish him, most of the time is searching for a book. Which features are using most?
    For example, my transparent button control, which is the main algorithm is how to intercept the screen or intercept the form behind the control, including other objects with the picture.

    It's just a screen capture, window capture function. It took me at least half a day. Because windows forms has what is called a client area.If the computer also has DPI zoom or disable zoom. Intercepting pictures, but also different calculations, so far I have not solved it perfectly.

    I haven't found the perfect code on the forum.
    If need to search some picture frequently on the desktop,like ocr find text ,For example, make a universal installation software, automatically click on the tool, or some common screen operations, this need to be like ah, automatically identify picture background, click on the front desk, click on this tool.
    Gdiplus, you need to call a lot of APIs. Create a memory DC. Finally, you only need to make frequent calls to bitblt to get a screenshot.
    These tasks are very complex for people who do not have a lot of experience in image programming.
    Last edited by xiaoyao; Apr 9th, 2021 at 08:41 PM.

Posting Permissions

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



Click Here to Expand Forum to Full Width