|
tamir901 wrote: What i'm doing wrong???
At a guess, you are failing to supply a valid UpdateCommand.
More than that it is difficult to say without seeing the update code you are using.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
private void Form1_MouseMove(object sender, MouseEventArgs e)
{
Graphics g = this.CreateGraphics();
g.FillEllipse(Brushes.Red,
new Rectangle(e.X,e.Y,20,20));
}
Why do I get a funny location that is far from the mouse position and not even fixed!! It gets before and after the cursor position as I move!
Please help.
|
|
|
|
|
I see no humor in this
only two letters away from being an asset
|
|
|
|
|
Mark Nischalke wrote: I see no humor in this
Now THAT was funny!
In my post, by funny I meant strange.. You knew that.
|
|
|
|
|
The active pixel of the cursor by default is the top left of the cursor rectangle IIRC. I'm not sure if this can be changed (I think it can but I can't remember how).
This will centre your line at the cursor point.
private void Form1_MouseMove(object sender, MouseEventArgs e)
{
int widthHeight = 20;
using (Graphics g = this.CreateGraphics())
{
g.FillEllipse(Brushes.Red, new Rectangle(
e.X - (widthHeight / 2),
e.Y - (widthHeight / 2),
widthHeight,
widthHeight));
}
} [Edit] Just checked and the 'hot spot' pixel is set in the cursor file itself. I just downloaded this[^] to try it! [/Edit]
modified on Monday, October 5, 2009 4:29 PM
|
|
|
|
|
|
No problem
|
|
|
|
|
Wait
Actually, when applying your code to the form it works like a charm, but when doing the same to a pictureBox control, the same problem persists..
private void pbPreview_MouseMove(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
int HW = 20;
Bitmap b = (Bitmap)pbPreview.Image.Clone();
Graphics g = Graphics.FromImage(b);
g.FillEllipse(Brushes.Violet,
new Rectangle(
e.X - (HW / 2),
e.Y - (HW / 2),
HW,HW));
pbPreview.Image = (Image)b;
}
}
I tried using the HotSpot as you said but it's somehow a static point! I also tried this in the pain event handler of the pictureBox
private void pbPreview_Paint(object sender, PaintEventArgs e)
{
int HW = 20;
Graphics g = e.Graphics;
g.FillEllipse(Brushes.Yellow,
new Rectangle(
this.Cursor.HotSpot.X,
this.Cursor.HotSpot.Y,
HW, HW));
}
Please Dave, let me know if you still have a trick up your sleeve
|
|
|
|
|
your mouse pos is always relative to something. You need to work out what it's relative to, and what you want it to be relative to. I'd guess you need to just subtract the top left corner of the picturebox, and that you're getting co-ordinates on the form. However, there are ClientToScreen and ScreenToClient type methods on your controls which you can use.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
Christian Graus wrote: mouse pos is always relative to something...
subtract the top left corner of the picturebox...
Exactly my thought but I was disappointed when it didn't work
Christian Graus wrote: there are ClientToScreen and ScreenToClient type methods on your controls which you can use.
I will give them a try, thank you for your time Christian..
|
|
|
|
|
This works for me - all I've done is call pictureBox1.CreateGraphics instead.
private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
{
int widthHeight = 20;
using (Graphics g = pictureBox1.CreateGraphics())
{
g.FillEllipse(Brushes.Red, new Rectangle(
e.X - (widthHeight / 2),
e.Y - (widthHeight / 2),
widthHeight,
widthHeight));
}
}
|
|
|
|
|
Thank you Dave!! Man you are amazing
|
|
|
|
|
This is an improved implementation that does what you want by creating a custom picture box. There's still some stuff to do, such as validating the value of LineWidth etc but should help.
public class DrawablePictureBox : PictureBox
{
private List<Rectangle> rectangles = new List<Rectangle>(100);
public DrawablePictureBox()
{
LineWidth = 20;
LineColor = Color.Red;
}
public int LineWidth
{
get;
set;
}
public Color LineColor
{
get;
set;
}
protected override void OnMouseMove(MouseEventArgs e)
{
base.OnMouseMove(e);
if (e.Button == MouseButtons.Left)
{
Rectangle rectangle = new Rectangle(e.X - (LineWidth / 2),
e.Y - (LineWidth / 2),
LineWidth,
LineWidth);
rectangles.Add(rectangle);
Invalidate(rectangle);
}
}
protected override void OnPaint(PaintEventArgs pe)
{
base.OnPaint(pe);
if (rectangles.Count > 0)
using (Brush brush = new SolidBrush(LineColor))
{
foreach (Rectangle rectangle in rectangles)
pe.Graphics.FillEllipse(brush, rectangle);
}
}
}
|
|
|
|
|
I've never come across Curor.HotSpot[^] before! It's a good one to have. It's not totally clear, but I assume it's the offset from the the top left ( 0, 0 or Point.Empty ) of the control's active cursor rectangle. Using this offset, combined with your line width and mouse position, will give you an accurate drawing point for whatever wierd cursor the user or you may have selected!
|
|
|
|
|
hi, I'am using one mainform and a custom control on it. The custom control consists of some textboxes and a custom progressbar with text.
The mainform properties(for your reference) are: FormBorderStyle=FixedSingle, MinimizeBox=False, MaximizeBox=False
The question is: when I click on other programs(when my mainform is not the active window) and reclick on my mainform, especially the custom progressbar doesn't update its text on it even though the value is updated. All other controls(numericupdown and textboxes) updates properly.
Thanks in advance
|
|
|
|
|
Is your custom control's OnPaint method getting called? If so, try calling CustomProgressBar.Invalidate(); in it.
|
|
|
|
|
yes it is. It works smoothly in general.It only doesn't update its text after making another program's window active and return back to my program again.
Also I already tried Update(), Invalidate() and Refresh() methods of both the mainform, custom control and the custom progress bar separately.
May the reason be the custom progressbar itself?
|
|
|
|
|
It could be. Is your custom progress bar's drawing taking place in an overridden OnPaint? If not, then that's the problem.
|
|
|
|
|
thanks Dave, I checked the source code and there isn't any overriden OnPaint() I will correct it and see if it works.
|
|
|
|
|
Hi to all:
Please could someone help me!
I am new to Silverlight but trying to get my head around the format and structure of it all.
I am experimenting with different ways of designing a web site and encountered the following problem.
What I am trying to do in a nutshell is to host a Silverlight control from a Silverlight application. To be more specific; from a *.Xaml file. My example is below:-
I am using a third party Silverlight control called Vertigo.Slideshow (I'm sure you will have heard of it).
From a website (Html coded page) I just do the following
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>Gallery</title>
<script type="text/javascript" src="../Scripts/Release/Silverlight.js"></script>
<script type="text/javascript" src="../Scripts/Release/SlideShow.js"></script>
</head>
<body>
<script type="text/javascript">
new SlideShow.Control(new SlideShow.XmlConfigProvider());
</script>
</body>
I then just add a Data.Xml file (with refs to all images) and also a Configuration.Xml to my current folder. This all works perfectly fine.
However, I've created a new web site in Visual Studio 2008 using 'Silverlight Navigation Application'.
So all my web pages are in the *.Xaml format.
What I'm trying to do is add this Vertigo.Slideshow.Xap control to my web page (Xaml) but really, really struggling. I know I must be doing something fundamentally wrong but cannot seem to resolve it.
I would really appreciate any help whatsoever to anyone who can shed some light on this (or even a snippet of code which will do this).
I would be eternally grateful to whomever gives me a pointer.
Thanks in advance.
Regards
Richard
|
|
|
|
|
Why did you repost this here? You already asked in the correct forum.
only two letters away from being an asset
|
|
|
|
|
HI everyone,
I really need to know how to make compatable with different version of excel application.
I have a application which uses the latest verion excel and it work fine. but when I try to run on any lower version excel it does not work.
thanks in advance.
jashim
|
|
|
|
|
jashimu wrote: I have a application which uses the latest verion excel and it work fine. but when I try to run on any lower version excel it does not work.
Move the version-dependent code to a DLL, and make one for each version of Excel that you wish to support
I are Troll
|
|
|
|
|
Hi Eddy,
I am not sure what are you saying. Can you please give me littile more hints and if possilbe details. I am not an expert yet.
thanks for your help.
Jashim
|
|
|
|
|
Can you separate the importing-code from your application, into a class-library? If so, then you can make a class-library with the appropriate code for each version of Excel.
You're looking for a plug-in system, I guess
I are Troll
|
|
|
|