|
A second grade astronaut might consider a TableLayoutPanel, I haven't used it so far.
|
|
|
|
|
hi everyone iam a C# programmer iam not profrssional
i want to make a program like MS paint , i will use C#
i need this program
i tried to make but when i draw any thing on the picture box all what i drawed cleared when i move the form
please reply me
thanks
Mohammed Mahmoud
|
|
|
|
|
Hi,
A PictureBox is just good enough for displaying an image, no more, no less.
If you want to draw onto something, chose a Panel.
There are several CP articles about Paint apps; and there is paint.net[^]
|
|
|
|
|
thanks mr Luc Pattyn
iam use a panel too, but again when i drawing any thing and move the form or when i minimize it the drawing is clear
please excuse me my english langauge is not good
thanks and i wish u reply me
|
|
|
|
|
Here is my standard advise on painting:
there are several steps to correctly draw something so it becomes visible on the screen:
1.
decide upon what object you want to draw; it normally is a Control (e.g. a Panel) or a
Form itself. I prefer to add a Panel to a Form, then draw on the Panel.
2.
create some variables (Rectangle, struct, class, whatever) that hold the parameters of
your drawing. For a rectangle that could be top and left coordinate, and width+height,
or just a Rectangle. etc.
3.
create a Paint handler (either add your own paint handler to the Paint event, or
override the OnPaint method) for that Panel, and do all your drawing in there,
using the Graphics class and your variables.
4.
when you want to change things, modify the variables and call Panel.Invalidate() or
one of its overloads (for selective invalidation).
5.
If you want to animate things, perform the move (step 4) inside the Tick handler
of a Windows.Forms.Timer
BTW: if you need to create some objects (Fonts, Pens, Brushes, ...) either keep them
alive in class members (hence create them only once); or create them inside the Paint
handler and don't forget to call Dispose() on them.
I trust the CP articles do it this way...
|
|
|
|
|
thanks
but all what i need that when click on a button the program draw a ecllipse on the drawing area on a point that i will enter it on a text box
that is what i need
can you help me on it
thanks for your interested
|
|
|
|
|
thanks
but all what i need that when click on a button the program draw a ecllipse on the drawing area on a point that i will enter it on a text box
that is what i need
can you help me on it
thanks for your interested
thanks
|
|
|
|
|
Here is my standard advise on painting, no matter what exactly you want to paint or draw:
there are several steps to correctly draw something so it becomes visible on the screen:
1.
decide upon what object you want to draw; it normally is a Control (e.g. a Panel) or a
Form itself. I prefer to add a Panel to a Form, then draw on the Panel.
2.
create some variables (Rectangle, struct, class, whatever) that hold the parameters of
your drawing. For a rectangle that could be top and left coordinate, and width+height,
or just a Rectangle. etc.
3.
create a Paint handler (either add your own paint handler to the Paint event, or
override the OnPaint method) for that Panel, and do all your drawing in there,
using the Graphics class and your variables.
4.
when you want to change things, modify the variables and call Panel.Invalidate() or
one of its overloads (for selective invalidation).
5.
If you want to animate things, perform the move (step 4) inside the Tick handler
of a Windows.Forms.Timer
BTW: if you need to create some objects (Fonts, Pens, Brushes, ...) either keep them
alive in class members (hence create them only once); or create them inside the Paint
handler and don't forget to call Dispose() on them.
|
|
|
|
|
ok mr Luc Pattyn
but iam try what u say but unuseful
please i want you to send me a code to draw a ecllipse in a panel or if u can send me a project of this
sorry iam tired u , but u r a very good person
thanks for ur advice
|
|
|
|
|
private int x = 0;
private int y = 0;
private int width = 200;
private int height = 100;
private Pen pen=Pens.Black;
public myForm() {
InitializeComponents();
Panel p=new Panel();
Panel.Bounds=...;
Controls.Add(p);
p.Paint+=paintHandler;
...
}
private void paintHandler(object sender, PaintEventArgs e) {
Graphics g=e.Graphics;
g.DrawEllipse(pen, x, y, width, height);
}
That is all you are going to get.
Read some articles, or better yet buy and study a book on C#.
|
|
|
|
|
thanks mr Luc Pattyn
ur code is very good but please i want to click a button to do this
thanks
|
|
|
|
|
This button[^] does everything you want.
|
|
|
|
|
ok but when i put the code in the button event handler the same thing hapened to me the drawings cleared
|
|
|
|
|
It is clear that you do not have the skill or knowledge to attempt this simple task.
May I suggest doing something easier, start with the basics, such as a loop counting to 10?
My failometer is detecting vast quantities of FAIL!
|
|
|
|
|
This forum is full of people at least as lost as you, so don't be upset. But, you're really lost and out of your depth. It's obvious you didn't follow the example given to you, because the reason the drawings clear, is that you used the wrong method to generate a graphics object. If you draw in your paint event, the image will not clear, it can't. So, buy a book, start with the basics, and approach this task when you know enough C# to understand the help offered to you.
Christian Graus
Driven to the arms of OSX by Vista.
"I am new to programming world. I have been learning c# for about past four weeks. I am quite acquainted with the fundamentals of c#. Now I have to work on a project which converts given flat files to XML using the XML serialization method" - SK64 ( but the forums have stuff like this posted every day )
|
|
|
|
|
i have tried using below coding for shopping cart functionality...but it shows below error...
Error:
CS0501: 'CartItem.Quantity.get' must declare a body because it is not marked abstract or extern
Coding
using System;
public class CartItem : IEquatable<cartitem> {
#region Properties
public int Quantity
{
get;
set;
}
private int _productId;
public int ProductId
{
get
{
return _productId;
}
set
{
_productId = value;
}
}
private Product _product = null;
public Product Prod
{
get
{
if (_product == null)
{
_product = new Product(ProductId);
}
return _product;
}
}
public string Description
{
get
{
return Prod.Description;
}
}
public decimal UnitPrice
{
get
{
return Prod.Price;
}
}
public string productname
{
get
{
return Prod.Productname;
}
}
public decimal TotalPrice
{
get
{
return UnitPrice * Quantity;
}
}
#endregion
public CartItem(int productId)
{
this.ProductId = productId;
}
public bool Equals(CartItem item)
{
return item.ProductId == this.ProductId;
}
}
</cartitem>
|
|
|
|
|
reread the error message, then compare the code for properties Quantity and ProductId.
What you have is called an "auto-implemented property", which is rather new.
Either fix the code or switch to the latest .NET version and rebuild.
|
|
|
|
|
Hi,
I've created a listview in wpf, filled it with data and tried to select different rows. However, when I click a row in the listview, selectionchanged event triggers only first time and first row gets selected. The second time i click a row, events like PreviewMouseLeftButtonDown get triggered, but not selectionchanged. In the listview.view i have a gridview with 3 gridviewcolumns. It's like the routed event gets handled at listview click and does get to selectionchanged event. Could you help me, please? I even tried different selection modes, but it's not related to it.
|
|
|
|
|
This code did the trick
private void lvAppointments_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
DependencyObject dep = (DependencyObject)e.OriginalSource;
while ((dep != null) && !(dep is ListViewItem))
{
dep = VisualTreeHelper.GetParent(dep);
}
if (dep == null) return;
lvAppointments.SelectedItem = dep;
}
But could someone explain me why do i have to "hack" selectionchanged?
Thank you
|
|
|
|
|
Hi, guyz i want to create a web based app. quiz using VS 2005 C# code in ASP.NET, so who can help plz i don't know how 2 start
Appreciate the answers
|
|
|
|
|
If you can't use Google[^] then should you be programming at all?
Anyway, heres[^] a start.
My failometer is detecting vast quantities of FAIL!
|
|
|
|
|
Thanx man really helpful, but i want just a simple quiz using arrays not a database to retrieve questions or saving data.
|
|
|
|
|
Then I suggest you look at Arrays then. I trust you can Google[^] it yourself.
You didn't have to follow the tutorial word by word and connect to a database. It was ment as a guide to teach you the basics, which is what you asked for.
My failometer is detecting vast quantities of FAIL!
|
|
|
|
|
I'm sorry dude i searched i couldn't find something definite, now if want to create a question with four choices how can i do that just give 1 example so that i can apply it to the rest.
Thanx very much
|
|
|
|
|
string question = "How could you not find anything like this?";
string[] options = new string[]{ "Lazy", "Incapable", "Drunk", "All of the above" };
int answerKey = 3;
My failometer is detecting vast quantities of FAIL!
"Its SQL - hardly programming..." (Caslen)
|
|
|
|