Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
alealpha2000
@alealpha2000

@alealpha2000 maybe what is the issue?

I want to add a background image with a transparent dropshadow to a form in winforms. i managed to draw the background with UpdateLayeredWindow but now I'm stuck since apparently you have to draw the controls inside the form into the bitmap that is drawn with UpdateLayeredWindow

Joe4evr
@Joe4evr
ew winforms
can't you at least use WPF, since that has waaaaaaaaaaay better support for that kind of stuff?
alealpha2000
@alealpha2000
i can't rewrite the app so no
Joe4evr
@Joe4evr
then you're gonna have to live with the fact that drawing custom images in winforms is probably not gonna be worth the effort, if it's even possible in the first place
alealpha2000
@alealpha2000
i tried drawing the controls to the bitmap with Control.DrawToBitmap or sending the WM_PRINT message but when I do that UpdateLayeredWindow fails
Joseph Musser
@jnm2
@alealpha2000 You shouldn't need UpdateLayeredWindow unless the form itself is partially transparent, meaning you see other applications through your window area.
A background image with a transparent dropshadow on top of a solid background color can be done with the form's BackgroundImage property IIRC.
If you want see-through, you're in for a world of pain from what I remember making Windows Forms controls work on top of Aero glass.
I basically had to reimplement drawing and animated fades from scratch, calling into uxtheme's BeginBufferedAnimation etc
Joseph Musser
@jnm2
It was a cool effect for the two controls I did it to, RadioButton (with Appearance = Button) and TextBox. But it does not scale.
alealpha2000
@alealpha2000

A background image with a transparent dropshadow on top of a solid background color can be done with the form's BackgroundImage property IIRC.

that didn't work because i can't set the backgroundcolor to transparent so the backgroundcolor is shown

anyway i have another more important issue
i changed the backgroundimage of a user control in the visual studio designer but when i build and run the app the old backgroundimage is shown. i tried removing the old background image from resources, deleting the old background image file, deleting the .vs folder, deleting the /bin and /obj folders nothing worked
Joseph Musser
@jnm2
If what you see when you run doesn't match the designer, it means that you're setting the image manually in code somewhere.
alealpha2000
@alealpha2000
i deleted the image from resources so there should be a compile error when i build the app and there isn't one
Joseph Musser
@jnm2
Or maybe you're failing to build and you have VS set up to run the last-built copy of the app when the build fails?
It's definitely plausible that the image got added to project resources or form resources more than once.
Joseph Musser
@jnm2
If all else fails, you can search the solution for the text BackgroundImage and place a breakpoint on each line.
alealpha2000
@alealpha2000
it turns out the old image was still in the form resources. thanks!
i have one final issue. i am making a custom button. i can't detect when the button is hot or pressed to change how it is drawn
private void SimulateTransparency(PaintEventArgs pevent)
        {
            //simular transparencia
            var graphicsContainer = pevent.Graphics.BeginContainer();
            pevent.Graphics.TranslateTransform(-Left, -Top);
            var paintEvents = new PaintEventArgs(pevent.Graphics, Bounds);
            base.InvokePaintBackground(Parent, paintEvents);
            base.InvokePaint(Parent, paintEvents);
            pevent.Graphics.ResetTransform();
            pevent.Graphics.EndContainer(graphicsContainer);
        }
        protected override void OnPaint(PaintEventArgs pevent)
        {
            int radius = 5;
            SimulateTransparency(pevent);
            pevent.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
            Color fillColor, textColor;
            if (AccessibilityObject.State == AccessibleStates.HotTracked)
            {
                fillColor = ControlPaint.Light(BackColor);
                textColor = ForeColor;
            }
            else if (AccessibilityObject.State == AccessibleStates.Pressed)
            {
                fillColor = ControlPaint.Dark(BackColor);
                textColor = ForeColor;
            }
            else if (!Enabled)
            {
                fillColor = ControlPaint.LightLight(BackColor);
                textColor = ControlPaint.Light(ForeColor);
            }
            else
            {
                fillColor = BackColor;
                textColor = ForeColor;
            }
            using (var path = RoundedRect(ClientRectangle, radius))
            using (var backBrush = new SolidBrush(fillColor))
            using (var frontBrush = new SolidBrush(textColor))
            {
                pevent.Graphics.FillPath(backBrush, path);
                pevent.Graphics.DrawString(Text, Font, frontBrush, ClientRectangle, stringFormat);
                if (Focused && ShowFocusCues)
                {
                    var rect = ClientRectangle;
                    rect.Inflate(-radius, -radius);
                    ControlPaint.DrawFocusRectangle(pevent.Graphics, rect, ForeColor, BackColor);
                }
            }
        }
Joseph Musser
@jnm2
@alealpha2000 That's always been something I've had to manage manually using MouseEnter/Leave/Up/Down/Move events
If all you need to track is the hot state and there is no subrange of the control pixels to worry about, MouseEnter/Leave setting a private isHot variable should do the trick.
@alealpha2000 Instead of Graphics.DrawString, consider using the TextRenderer class. That gives better ClearType rendering.
Paul M Cohen
@paul1956
@jnm2 is there an easy way to convert a StringFormatFlags to TextFormatFlags used by TextRenderClass? Will a Cast work?
TextRenderer.DrawText does not take a StringFormat object
Joseph Musser
@jnm2
Not as far as I know. StringFormatFlags is about a GDI+ API and TextFormatFlags is about a GDI API.
See https://stackoverflow.com/a/6404811 for a nice full comparison too.
Paul M Cohen
@paul1956
Thanks that helps a lot, I think I will take it in small chunks.
Paul M Cohen
@paul1956
image.png
image.png
I just got a new PC with a high resolution display and the the same binary app displays ToolStripComboBox and ToolStrip both display very unexpectedly. The height of the MenuStrip and ToolStrip is much large and the ComBox is displaying as a list box.
Joseph Musser
@jnm2
There have been some improvements, but I've never found a good strategy for DPI flexibility with winforms.
Jeremy Kuhne wants to tackle the issues it has eventually: https://youtu.be/m-NdyJVBf2Y?t=1388
Paul M Cohen
@paul1956
@jnm2 you mean this is expected? I can’t even understand what it’s doing to try to workaround it for the 3 broken controls.
@jnm2 forgot I was the video. I will fine some bugs.
Andy Green
@Ydiren
Hi guys. I'm having problems with FileSystemWatcher locking directories, so have been looking for alternatives. I've come across the PollingFileSystemWatcher here in the dot net source browser, but can't find any reference to it in the official docs. I see that the class has been around in the corefxlabs repo for quite some time, does anybody know if this is ready for use and if so, where I can find the binaries to reference?
Joe4evr
@Joe4evr
since it's on corefxlab, there's no binary available (if I understand the purpose of the lab repo)
Andy Green
@Ydiren
That's what I had assumed, but the fact that the code is also in the MS source browser website made me think this was readd
*ready for use!
Joe4evr
@Joe4evr
it's easy enough to clone the corefxlab repo and reference the Polling project yourself to try it out
Andy Green
@Ydiren
Ok, at least I'm not missing anything obvious. Thanks for the pointers.
Joe4evr
@Joe4evr
ah, there's a seperate nuget feed you could pull it from (see dotnet/corefxlab#2804 )
Andy Green
@Ydiren
Thanks again, you've been most helpful! :-)
lambrech
@lambrech
Hi all, I have a short question, and I hope this is the right place to ask it:
It is about the C# 8 nullable feature. Is there a way to mark a referenced library or nuget paket as "null-oblivious"?
Because I have the "Nullable"-feature enabled and I really like it a lot. Sadly most of the packages I am using did not implemente nullable awareness yet.
Joe4evr
@Joe4evr
the compiler should be able to see a referenced library is null-oblivious because it will lack the assembly-wide marker attribute
Jose
@pepone
I building a library and packaging it as NuGet package, then when I use it in an application, the exceptions from the library doesn't show up the line numbers, I have try to include the PDBs in the NuGet package but still not luck, is there a way to get the library line numbers when printing exceptions from an application that uses the library NuGet package?
Igor Velikorossov
@RussKie
@pepone do you package a debug or release version of your lib?
Jose
@pepone
@RussKie It is a debug build I build with DebugType=portable Optimize=false DebugSymbols=true
Matthijs ter Woord
@mterwoord
net47 doesn't seem to understand portable format for that