I have an Indian flag cursor like sym66.cur and I used it in C# code. It is running
but it is not getting in proper image. Instead, it is getting a black image. How can make the cursor display in the proper format?
This is my code:
private void New_Registration_Load(object sender, EventArgs e)
{
this.Cursor = new Cursor(Application.StartupPath + "\\sym66.cur");
}
Q: Do you see a black square instead of a cursor ... or is your color cursor displaying in black and white.
The WinForms "Cursor" only supports black and white, not color:
http://msdn.microsoft.com/en-us/library/system.windows.forms.cursor%28v=vs.110%29.aspx
The Cursor class does not support animated cursors (.ani files) or cursors with colors other than black and white.
Related
I would like to be able to fill any given area of an image with a given color, much like you can use paint to fill a rectangle, circle or any other shape delimited by a color.
To make this simpler I already have made the picture box source image to have the same size as the picture box itself, which should make things a bit easier.
How can I do this given that I have a picture box with an image and an already defined color and the user only has to click over the picture box to fill in any area with such color.
void pictureBox1_MouseClick(object sender, MouseEventArgs e)
{
// The color to be used
Color color = Color.Red;
// Image has same dimensions as picturebox to make things easier
Image img = pictureBox1.Image;
// Where it was clicked.
Point clickCoords = new Point(e.X, e.Y);
// Coloring that area clicked much like Paint does. How?
...
// After coloring show the result in the picture box again
pictureBox1.Image = img;
}
Thanks.
EDIT: Example of my desired behavior.
To make my goal obvious, let me add this small example.
You know MS Paint right?
You selected the pencil tool and start doing anything on the canvas, doesn't matter form or shape or even if the points your are doing with the pencil are connected or not.
Now you select the bucket tool and start clicking on the canvas. What will it do? Fill in the selected area according to the color you clicked over and how far she goes without changing with the color you have selected on the color pallet.
This is the behavior I want to emulate on my picture box mouse click event.
What you are looking for is a flood-fill algorithm. This should do the trick just fine.
The algorithm recursively searched for neighboring uncolored pixels, until it hits a wall.
You can use the code from here:
// Load the image (probably from your stream)
Image image = Image.FromFile( imagePath );
using (Graphics g = Graphics.FromImage(image))
{
Color customColor = Color.FromArgb(50, Color.Gray);
SolidBrush shadowBrush = new SolidBrush(customColor);
g.FillRectangles(shadowBrush, new RectangleF[] { rectFToFill });
}
image.Save( imageNewPath );
, but there is a one thing you missed - a rectFToFill, which you should define according your click event. There are a lot of strategies you can use, I suggest you to handle a Drag event or something like that, save the event start point and end point, after that define the rectangular you must fill:
You should examine the event points and after that create the Rectangle(F) structure using some of its constructors.
The Graphics class has a dozen methods you can use to draw some shapes or lines on your Image.
I am trying to set the form's background as invisible as I want the background image to be the thing that has the transparency.
I have used multiple background colours; - lime, magenta, red, white with the same transparency key but they all give me a horrible result. You can see that I have set the backcolour to be yellow, and the transparency key to yellow but at the top there is still yellow
I have also used
SetStyle(ControlStyles.SupportsTransparentBackColor, true);
this.BackColor = Color.Transparent;
That didn't work either and neither did
protected override void OnPaintBackground(PaintEventArgs e) { /* Ignore */ }
Does anyone have a way that I can do this?
The idea of my project is to show solid text on a transparent form control.
I have used this technique to make the form transparent:
BackColor = Color.Lime;
TransparencyKey = Color.Lime;
The problem I'm having is coloured edges around the text. I've tried drawing anti-aliased text using graphics and displaying the text using labels but neither worked. I still have disgusting-looking, pixelated, lime edges around my text.
I looked around a little - posts are usually concerned with making the form transparent not dealing with this issue.
You can get reasonable output by using TextRenderingHint.AntiAliasGridFit.
private void TestForm_Paint(object sender, PaintEventArgs e) {
e.Graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAliasGridFit;
e.Graphics.DrawString("Header", this.Font, SystemBrushes.WindowText, new Point(1, 1));
}
But if you plan on using large fonts, it won't render too well since it can't really antialias properly.
The nature of fonts, in general, is to have a background to draw on. If you have black text on a transparent form, and the end user has a black background-- the end user isn't going to see anything.
I am writing a program in Visual C# 2010 that has several icons on the form. When the mouse is placed over the icon (which is just an image) I want the icon to b highlighted via a border around the icon. In visual basic i can make a transparent rectangle with a colored border and position it over the icon. In C#, i can do the same however until i call invalidate multiple borders appear. The problem with calling invalidate is that my program is doing something in the background every second so the border keeps flashing (re-drawing).
Anyone got any ideas how i can implement this?
You didn’t say how you draw the border but from your description you are creating a graphics context for this. Don’t do this, it’s wrong. Instead, draw inside the Paint element of either the control or the its parent container.
The Paint event handler could look as follows:
private void yourControl_Paint(object sender, PaintEventArgs e)
{
if (! HasFocus(yourControl))
return;
Graphics g = e.Graphics;
using (Pen p = new Pen(Color.FromArgb(128, 0, 0, 128)))
g.DrawRectangle(p, 0, 0, yourControl.Width -1, yourControl.Height - 1);
}
This uses a hypothetical HasFocus method to determine whether this control should have a focus rectangle.
By the way, this is identical in VB and C#.
Figure 1,i have one or a few pictures,and some mp3 files. i want to develop a winform and load picture into winform,then, when mouse over certain areas of the picture,the area change,and play mp3 file when the mouse click.
question:How do I know the mouse over the designated area?and then change the color of the area? how to know which areas of mouse clicks? and play mp3 files
These areas may be round, oval, rectangular...
perhaps this is hotspot image question.
anyone help me? thanks!
Use OvalShape and the MouseHover event. Then simply call code to modify the opacity/color/whatever of the oval, and play an mp3 which is a separate problem.
One way to do that is to create a hidden bitmap of the same size with a white or black background, and shade each bubble with a different color.
Then you can just do something like this:
private void Form1_MouseMove(object sender, MouseEventArgs e)
{
int foundColor = _Mask.GetPixel(e.X, e.Y).ToArgb();
if (foundColor == Color.Red.ToArgb())
// do something with this bubble
else if (foundColor == Color.Blue.ToArgb())
// do something with this bubble
else
// do nothing
}