dcsimg
Results 1 to 2 of 2

Thread: [RESOLVED] RotateTransform gradient not in sync

  1. #1

    Thread Starter
    Super Moderator RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,568

    Resolved [RESOLVED] RotateTransform gradient not in sync

    So doing some drawing in a drop down and when I dont transform it it draws as expected. However when I transform the brush 90 degrees, for ex. it seems to also transform the rectangle. However if I adjust for that then it draws outside the border as if the rectangle isnt transformed. I think my rectangle and brush rectangle are out of alignment causing it to tile or draw out of the border.

    Its an 11 x 10 pixel rectangle and the first column of pixels is the "margin" resulting in a 10 x 10 square.

    No transform
    Name:  Unsure1.png
Views: 198
Size:  2.6 KB

    Transform 90
    Name:  Unsure2.png
Views: 191
Size:  2.1 KB

    Transform 45
    Name:  Unsure3.png
Views: 188
Size:  6.5 KB



    Code:
    Pen pen = new Pen(Color.Black, 1);
    Graphics rectGraphics;
    Bitmap img = new Bitmap(11, 10);
    rectGraphics = Graphics.FromImage(img);
    rectGraphics.DrawLine(pen, 2, 0, 9, 0); //rounded rectangle
    rectGraphics.DrawLine(pen, 10, 1, 10, 8); //rounded rectangle
    rectGraphics.DrawLine(pen, 9, 9, 2, 9); //rounded rectangle
    rectGraphics.DrawLine(pen, 1, 8, 1, 1); //rounded rectangle
    
    Rectangle innards = new Rectangle(2, 1, 8, 8);
    LinearGradientBrush lgb = new LinearGradientBrush(innards, Color.White, Color.White, 0, false);
    
    ColorBlend cb = new ColorBlend();
    cb.Positions = new[] { 0.0f, 0.5f, 1.0f };
    cb.Colors = new[] { Color.White, Color.Pink, Color.Red };
    lgb.InterpolationColors = cb;
    lgb.RotateTransform(90);
    
    rectGraphics.FillRectangle(lgb, innards); //fill rectangle innards
    pen.Dispose();
    rectGraphics.Dispose();
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Star Wars Gangsta Rap Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Corsair H100i v2 water cooler, Geforce GTX1060, Samsung M.2 500 GB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2010, VS 2010

  2. #2

    Thread Starter
    Super Moderator RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,568

    Re: RotateTransform gradient not in sync

    Never fails, soon as I post a thread I figure it out.

    So seems an overload of the LinearGradienBrush has an angle argument. So I changed to that overload and commented the RotateTransform and it works as needed now.


    Changes:
    Code:
    LinearGradientBrush lgb = new LinearGradientBrush(innards, Color.Black, Color.Black, 45);
    ...
    ...
    //lgb.RotateTransform(90);
    Name:  Unsure4.png
Views: 22
Size:  6.5 KB
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Star Wars Gangsta Rap Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Corsair H100i v2 water cooler, Geforce GTX1060, Samsung M.2 500 GB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2010, VS 2010

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width