WinAPI: Draw rectangles behind Edit Control text - c

I have a read-only Edit Control that displays a multiline string. I set the background color for it using WM_CTLCOLORSTATIC in the window procedure of the dialog that my control is subclassed from. If the window is shrunk, scrolllbar appears for the Edit Control. It all works fine, you can select, copy, scroll the text left and right.
case WM_CTLCOLORSTATIC:
if ((HWND)lParam == GetDlgItem(hwndDlg, IDC_DEBUGGER_DISASSEMBLY))
{
SetBkColor((HDC)wParam, RGB(255, 255, 255));
return (LRESULT) GetStockObject(DC_BRUSH);
}
break;
I want to make custom background color behind a particular line. My normal BG is white there, and for that line I want, say, blue.
I tried using WM_PAINT for the Edit Control, but then I seem to have to draw the text once again, or the original text of the control won't be visible until I select it. And if I manually draw text too, it won't scroll the same as the original text.

If you absolutely have to have an edit control, then I don't see a solution. However, with some tweaking, you might be able to use a rich edit control. It accepts most of the same messages as an edit control. The trick would be using SetCharFormat to set the format of the line you want to change.

Related

Need overlapping button in round cornered Winform

Need a quick suggestion for styling a WinForm. I made it with rounded corners even when re-sized. Now trying to add a close button with a image (ControlBox=false), overlapping or clipped to top right corner. This is what I could end with.
But I wish to make it more like in this example image.
How could I achieve this in WinForm.
Here's the trick : your window doesn't just end with the white part. It extends a little bit further. The close button comes under the 'extra' part. The other sides where the window appears to not be there is actually transparent...or in the case of the image, semi-transparent.
The glow effect is provided by the window. Set the TransparencyKey property of the window to Color.Magenta (its a convention as Magenta is the color least likely to be used in a window). Then set the background image to a white background with a little bit of Magenta in the edges. The Magenta will appear transparent when set as the background image.
Fiddle around with TransparencyKey and you'll understand what I mean
Winforms itself cannot provide this for you without outside manipulation of the windows,
because it still uses win32 windows classes in the background.
If you want transparancy in windows: see articles like:
Cool, Semi-transparent and Shaped Dialogs with Standard Controls
And the method in Win32 to do it:
SetLayeredWindowAttributes

WPF Input Method Editor

I'm trying to enable the IME in WPF... which works for some textboxes but not the one I actually need it for. I do the following in XAML
InputMethod.IsInputMethodEnabled="True" InputMethod.PreferredImeConversionMode="Native" InputMethod.PreferredImeState="On"
I have a custom on-screen keyboard, the textbox has focus, and keys can be pushed on the screen and send the appropriate letter to the textbox. But when setting this above xaml to the textbox in this custom keyboard, the candidate window doesn't display at all, instead a strange small black control appears on the top left of the screen with a text box and a green arrow which has a caption of "Enter". Any text pressed on the keyboard goes to that small black control without showing the text, but after pressing enter, that text appears in my keyboard.
Ultimately I'm trying to incorporate simplified Chinese. Again, this works perfect on every other textbox but the one I actually need it for, being the custom onscreen keyboard.
Any thoughts? I'm really stuck with this.
Cheers.
UPDATE
This is the image I see, don't scroll down, it's the black little control with the green arrow.
http://babelstone.blogspot.ca/2010/05/prototyping-tangut-imes-or-why-windows.html
So I've been looking for a different design of the IME, Notepad seems to show something different. But I eventually got the little black box control to work and display what I'm actually typing. Moved xaml to code behind and it started working.

change the color of the png image using expression blend

There might be duplicates of this question but I didnt find any exact solution to my problem.
I have an image. The source of image is a png image named add.png. The shape of add.png is like a plus(+) symbol. Its color is white at the moment.
I want to change this white color to green when mouse cursor goes over it. So which property of the image should I change to change its color.
I don't want to change the source of image.
Edit :
Why I don't want to change the image source :
Basically I have a rectangle and I keep the image over it.
On MouseOver and MouseLeave I change the Fill color of Rectangle using ChangePropertyAction. Now When I click on the image I want to change its source.
But when my program runs I get an error sayin that windows explorer has stopped working.
When I see the output window for errors I get System.NullReferenceException: Object reference not set to an instance of an object
It is easier. to change the image source.
Your options are limited here: Create own effect by derive from System.Windows.Media.Effects.Effect, call it ColorEffect and implement color change logic there, a similar alternative would be to create separate PixelShader Effect but this is more complex then the Effect above.
Use image processing from http://www.codeproject.com/Articles/237226/Image-Processing-is-done-using-WPF

Winforms semi-transparent PNG over semi-transparent PNG

I think I must be missing something obvious, but I'm unable to find this after several hours of searching. Is there no way to use a PictureBox or other control to contain an image with partial transparent/alpha-blended pixels, and place that over another image and have the blending be based on the image under it?
For example, this produces the results I want:
Place a panel on a form.
Add an OnPaint handler.
In the OnPaint handler draw 1 PNG, then draw another PNG over it, using Graphics.DrawImage for both.
This does not:
Place a PictureBox on a form and set it to a PNG.
Place another PictureBox on the form and set it to a PNG.
Place the 2nd picture box over the first.
...even if the 2nd picture box is just empty and has a background color of Transparent, it still covers the picture below it.
I've read this stems from all winform controls being windows, so by nature they aren't transparent.
...but even the 15 year old platform I'm migrating from, Borland's VCL, had several windowless controls, so it's hard to imaging winforms doesn't at least have some easy solution?
My first example above is one answer, true, but that adds a lot of work when you can only use one big panel and draw all of your "controls" inside of it. Much nicer if you can have separate controls with separate mouse events/etc. Even if not an image control, and a control I have to draw myself, that would be fine, as long as I can just put one image in each control. In VCL they called this a "paint box", just a rectangle area you could place on a form and draw whatever you want on it. Has it's own mouse events, Bounds, etc. If you don't draw anything in it, it is like it's not even there (100% transparent) other than the fact it still gets mouse events, so can be used as a "hot spot" or "target" as well.
The PictureBox control supports transparency well, just set its BackColor property to Transparent. Which will make the pixels of its Parent visible as the background.
The rub is that the designer won't let you make the 2nd picture box a child of the 1st one. All you need is a wee bit of code in the constructor to re-parent it. And give it a new Location since that is relative from the parent. Like this:
public Form1() {
InitializeComponent();
pictureBox1.Controls.Add(pictureBox2);
pictureBox2.Location = new Point(0, 0);
pictureBox2.BackColor = Color.Transparent;
}
Don't hesitate to use OnPaint() btw.
Sorry, I just found this... once I decided to Google for "winforms transparent panel" instead of the searches I was doing before, the TransPictureBox example show seems to do exactly what I need:
Transparency Problem by Overlapped PictureBox's at C#
Looks like there are 2 parts to it:
Set WS_EX_TRANSPARENT for the window style
Override the "draw background" method (or optionally could probably make the control style Opaque).

text in paint like application

Hope I can make the question clear.
I am working on a paint like application where users can add different objects and also text. The way to add text is that we show a dialog where user can enter text and then that text is added to the draw area.
Now we want that text should be added in the same way as in Power Point. A user clicks any where in the draw area, a rectangular text entering area is shown, where user can enter text, format it, move the rectangle to move the text and then click outside to enter the text on the drawing area.
Since the paint event of the draw area is called and every object is added to the draw area using graphics and paint, what is the best way to add text using the interface as I explained above.
Any suggestions would be appreciated.
Your best option is to place a TextBox as a child control and that will allow the user to modify the text as required. Once they finish changing the text you then remove the text box and draw the string instead. If they click the text becaues they want to change it then you put the text box back again so they can edit it.

Resources