|
I have a picture box, on which I detect mousemove events, and have the user draw on the picture box. Currently, I can save the image, but it's just plain white, without the actual drawing, any ideas where Im going wrong?
[CODE:]
private Graphics m_objGraphics;
private void pb_white_board_MouseMove(object sender, MouseEventArgs e)
{
Rectangle rectEllipse = new Rectangle();
if (e.Button != MouseButtons.Left) return;
rectEllipse.X = e.X - 1;
rectEllipse.Y = e.Y - 1;
rectEllipse.Width = 3;
rectEllipse.Height = 3;
m_objGraphics.DrawEllipse(System.Drawing.Pens.Black, rectEllipse);
Brush blackBrush = Brushes.Black;
m_objGraphics.FillEllipse(blackBrush, rectEllipse);
}
private void btn_save_whiteboard_Click(object sender, EventArgs e)
{
Bitmap bitmap = new Bitmap(pb_white_board.Width, pb_white_board.Height);
pb_white_board.DrawToBitmap(bitmap, new Rectangle(0, 0, pb_white_board.Width, pb_white_board.Height));
m_objGraphics.Save("image1.jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
}
Thanks, Ben.
|
|
|
|
|
Two things...
1 - You are not dwawing on a PictureBox and
2 - You are trying to fetch drawn image from the PictureBox where painting has not taken place...
Cheers
|
|
|
|
|
Where is m_objGraphics created? I guess that you're creating the Graphics object somewhere during initialization of your code and then use it later, which is a big no-no!
To do it correctly you have to call methods on a Graphics object you get from the Image displayed in the PictureBox:
private void pb_white_board_MouseMove(object sender, MouseEventArgs e)
{
if (e.Button != MouseButtons.Left) return;
Rectangle rectEllipse = new Rectangle(e.X - 1, e.Y - 1, 3, 3);
using (Graphics g = Graphics.FromImage(pb_white_board.Image))
{
g.DrawEllipse(System.Drawing.Pens.Black, rectEllipse);
g.FillEllipse(System.Drawing.Brushes.Black, rectEllipse);
}
pb_white_board.Invalidate();
}
Regards,
mav
--
Black holes are the places where God divided by 0...
|
|
|
|
|
Thanks, works a treat now
|
|
|
|
|
hi
i am use VC# 2005 and i want to connect to sqlserver 2000 from client to server,when i want to add datasource to my app and enter server name to
specific textbox and click Test connection the following error shown me :
Login failed for user 'VAZIRI-B8765F7F\Guest'.
I use Trusted Connection for connect to server
How to solve my problem ?
very thanks
|
|
|
|
|
Hi,
Are you sure that the credentials you supplied are correct ? (User name and password).
"A good programmer is someone who looks both ways before crossing a one-way street." -- Doug Linder
coolestCoder
|
|
|
|
|
Hi
When you use trusted connection it means that you are connectiong to sql server using windows authentication which means that you are connectiong using the user name that you have logged on with.(In this case Guest user)
therefore you should define the guest user in your SQL Server.
If you like you can use user and password keywords in your connection string to use Sql authentication instead of a trusted connection then you can use a sql server user (for example sa) to connect to Sql Server
Regards
|
|
|
|
|
Plz compile these programs for me & do tell me where r the errors.
WAP to take 2 dates using objects(day,month,year)& display both dates,their comparison also that which one is greater(take the dates with the help of three parameter constructors)
class demo
{
DateTime dt1=new DateTime(Monday,November 06,2006)
DateTime dt2=new DateTime(Wednesday,November 08,2006)
if(DateTime.compare(dt1,dt2)<0)
{
System.Console.WriteLine("Second date is larger than the first");
}
else if(DateTime.compare(dt1,dt2)==0)
{
System.Console.WriteLine("Second date is same as the first date");
}
else
{
System.Console.WriteLine("Second date is smaller than the first date");
}
}
-------------------------
class demo
{
private DateTime getDate(int day, int month, int year)
{
return new DateTime(year, month, day);
}
private void compareDates(DateTime a, DateTime b)
{
if (a > b)
Console.WriteLine(a.ToShortDateString() + " > " + b.ToShortDateString());
else if (a == b)
Console.WriteLine(a.ToShortDateString() + " = " + b.ToShortDateString());
else
Console.WriteLine(a.ToShortDateString() + " < " + b.ToShortDateString());
}
}
---------------------------
WAP that counts the no. of occurence of particular character in a line of text.
class demo
{
private int Occurance(string Input, string Find)
{
System.Text.RegularExpressions.Regex rx =
new System.Text.RegularExpressions.Regex(Find);
// to display them do this
System.Text.RegularExpressions.Match mt = rx.Match(Input);
while (mt.Success)
{
Console.WriteLine("Found >>" + Find + "<< at position " + mt.Index.ToString());
mt = mt.NextMatch();
}
// end display
return rx.Matches(Input).Count;
}
}
|
|
|
|
|
What?
Why don't you compile them yourself? You can use Visual Studio Express or the .NET Framework SDK to compile from command prompt. You can then easily check the errors and fix them.
modified 12-Sep-18 21:01pm.
|
|
|
|
|
I don't have compiler or Visual Studio at home.I have also tried to download SDK from microsoft but it is giving errors.
sorry for the inconvenience.
-- modified at 12:51 Saturday 11th November, 2006
|
|
|
|
|
It's pretty clear why this doesnt compile. Only variables, properties and methods can be placed inside a class. Everything else should be inside methods.
class Class1
{
public static void Main(String[] args)
{
}
}
WM.
What about weapons of mass-construction?
|
|
|
|
|
I didn't even try to compile the mess, I just looked at it. That's why the error messages are more to the point than the ones you would get from the compiler:
DateTime dt1=new DateTime(Monday,November 06,2006)
Variable 'Monday' is not defined.
'November 06' is not a valid expression.
There is no constructor for the DateTime structure that takes those arguments.
DateTime dt2=new DateTime(Wednesday,November 08,2006)
Variable 'Wednesday' is not defined.
'November 08' is not a valid expression.
There is no constructor for the DateTime structure that takes those arguments.
if(DateTime.compare(dt1,dt2)<0)
The operator is "Compare", not "compare".
Friend4u wrote: else if(DateTime.compare(dt1,dt2)==0)
The method is named 'Compare', not 'compare'.
---
b { font-weight: normal; }
|
|
|
|
|
Is there a way to specify a type contraint that operator== is supported?
or any way to deal with that?
We are a big screwed up dysfunctional psychotic happy family - some more screwed up, others more happy, but everybody's psychotic joint venture definition of CP
Linkify! || Fold With Us! || sighist
|
|
|
|
|
Off the top of my head, I can only think of:
where T : System.IComparable<T>
Geor
|
|
|
|
|
It was suposed to work for value types, too
We are a big screwed up dysfunctional psychotic happy family - some more screwed up, others more happy, but everybody's psychotic joint venture definition of CP
Linkify! || Fold With Us! || sighist
|
|
|
|
|
Have a look at the IEquatable interface.
---
b { font-weight: normal; }
|
|
|
|
|
peterchen, are you looking to just compare 2 reference types? If so,
bool AreEqual<T>(T first, T second)
where T : class
{
return first == second;
}
|
|
|
|
|
I wanted it to work for both reference nad value types, and use overloaded comparison operators if any - but that doesn't seem possible in C#.
I've replaced the template type with object, and use IComparable if implemented, otherwise I fall back to comparing the references.
thank you.
Developers, Developers, Developers, Developers, Developers, Developers, Velopers, Develprs, Developers! We are a big screwed up dysfunctional psychotic happy family - some more screwed up, others more happy, but everybody's psychotic joint venture definition of CP Linkify!|Fold With Us!
|
|
|
|
|
You have to use the IEquatable interface.
More information on the "operator in generics" problem: www.codeproject.com/csharp/genericnumerics.asp[^]
Quote: The solution uses the fact that constraining type parameters using interfaces is not the same as casting to interfaces. Calling a method using an interface has the overhead of dynamic method dispatch, but calling a method on a type parameter that is constrained by an interface has no such overhead.
|
|
|
|
|
Dear All,
Let me know about the basics of windows Remoting & COM programming.Regards.
Raihan Masud
|
|
|
|
|
You might want to take a look here.
Regards,
mav
--
Black holes are the places where God divided by 0...
|
|
|
|
|
i have a webpage with asp button. in server side, i wrote some code for its button click event to delete the page data.
but in client side i want user to confirm the deletion action. so i write this javascript code:
{if(confirm("do want to delete data...."))}
i don't know what to do to prevent page postback for false condition.
what should i do...
Thanks Rastgar
|
|
|
|
|
{if(!confirm("do want to delete data....")) return;
else do();}
|
|
|
|
|
i now 'if' parts and what 'return' does.
the thing that i don't know is how to stop my page from postback. but now i found it. to know that refer to my reply to guffa
Thanks Rastgar
|
|
|
|
|
Return a boolean in the click event of the button:
onclick="return confirm('Delete?');"
If the event returns false, the button click is stopped.
---
b { font-weight: normal; }
|
|
|
|