C# Windows Forms, painting combobox borders - c#

We need to show our disabled comboboxes as an image. The image has the same height as the standard combobox, but for some reason it cannot override the borders of the combobox.
Instead, it end up looking like this:
We would like them look like this image, i.e. that the image is shown on top of everything - including the combobox borders:
Any ideas?
Thanks.

First of all, what you are trying sounds really dirty - the best way would be, if your ComboBox would just look like your image as soon as you disable it!
If there is really no other way:
Create a PictureBox in front of your ComboBox. Set the image as the PictureBox's image, make it Visible whenever you want to "disable" your ComboBox.
But again, using controls to simulate behaviour you would expect to be part of another control is dirty.

Get the location of you textbox, set it invisible, then a the same location place an imagebox

Related

WinForm ComboBox Drawing Bug

I have a WinForm with TableLayoutPanel and ComboBoxes inside. Combo boxes expand by percantage size. And always after start application, left combobox has artifacts like these:
but the disappear as soon as I put a mouse on them. I have already tried different options, and the only thing that helps, is to set a constant size for all comboboxes, but that's not good for me.
That's how sizes looks like:
And how looks like typical scheme of my form:
Red squares - TableLayoutPanel with content;
Green squares - TableLayoutPanel without content, with margin 0, and single border.
Maybe somebody has ideas on how to fix this bug? Thanks.
So it's really a bug, but I found a simple solution.
Just subscribe to SizeChanged Event of parrent control/form and call Refresh() method in event handler. Control will be redrawn to the required size.

ToolStrip TextBox Colour

I have set up a ToolStrip in my C# WinForms project and have added a TextBox on it. I'm just curious whether it is normal that the TextBox is barely visible due to the colour of the ToolStrip and TextBox.
I could put a border around it or change the background colour of the TextBox but that just looks odd.
Is there some property which I haven't thought of which I could set to make it stand out more but not look out of place?
Screenshot added:
A very light border would probably be best. if you use the same color as the toolstrip, you won't really notice the border at the bottom, but it will make the top of the search box stand out. you might also want to add a margin around it, or less padding inside of it, so it doesn't fill up the whole hight.

C# Gray out a control and draw another on it

I´m using WinForms. I want to make a little class, which modifys controls to show it´s working.
I want to draw an overlay over for example a button. It should be a half-transparent gray.
After that i want to draw a ProgressBar on over it (in the center). Similar to This, except using a progress bar.
How can i realize this? I don´t want to set the position of the progressbar, just drawing it on the other one.
How could i do this?
Thanks :)
I have done something similar before.
You need to use Button.DrawToBitmap(Bitmap, Rectangle) to get the image of the button. Then make the Bitmap grayscale (there are multiple algorithms available for this; I have used the last one successfully although probably not originally from this site).
Now, I did this with an entire form instead of a button, but I disabled the form, and then covered the entire form with an image of itself, altered and then covered it with the progress bar (itself in a panel with other controls).
You could just as easily disable the button, cover it with a panel containing the image and the progress bar on top of it.

width of the dropdown arrow

So in winforms, every dropdown combobox has this little arrow thingy to the right that tells the user it's a dropdown, kinda like this:
Now how do I figure out how wide that is in pixels? Reason is, I'm using ControlDrawToBitmap, this doesn't draw the text properly for the combo boxes, and I can redraw the contents, I just whack some of the arrows (which are drawn properly).
First idea that comes to mind: Check to see if the combobox button width tracks with the scrollbar width. The scrollbar width can be modified in user preferences. Use GetSystemMetrics() API to get the width of the various scrollbar pieces. If you change your system scrollbar width and it does not affect the size of a normal combobox, then ignore this.
Second idea: use the edit control's formatting rect to find out what the edit control thinks is the usable display area (minus the combo box). See EM_GETRECT in MSDN.
However, it sounds like this is just a hack workaround for your real problem: If you could get the controls to draw correctly to bitmap, then you wouldn't need this hackery.
I calculated it to be 9 pixels wide in photoshop

create moving text

how can i make a text moving from top to bottom to top.... (like a news window) in a textBox
(Assuming windows forms)
I haven't tried to do this before, but my first attempt would include loading a bunch of text (like new headlines) into a textbox, and then making a timer that changes the vertical scroll value on the tick event? A textbox has built-in functions called ScrollToLine(), ScrollToVerticalOffset(), etc. Otherwise some controls, like panels have more direct access to scrollbar values. For example: SplitContainer.Panel1.VerticalScroll.Value = value;
If those don't work, you can always draw the text yourself via graphics object and then update the positions items are drawn at.
you can use javascript to do it for web and if it is windows have a look at this question . Hope it helps

Categories

Resources