|
ma_refay wrote: i write that code but it generate error why
What error?
By the way, what do you mean by date column; do you store string representations of dates or DateTime objects. In case of the latter you could directly assign them to the DateTimePicker without turning them into a string representation and then reparsing to a DateTime object.
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook www.troschuetz.de
|
|
|
|
|
Hi,
I'm a newbie and am working on this project for about a week now. I need to create a Dog class where the user will be able to interact with the class using "Pet (dog not angry), Tease(dog angry), Feed(dog not hungry), Age(dog hungry), GoToSleep(dog asleep) and WakeUp(dog not asleep).
This is the code in my Dog class
[CODE]
class Dog
{
private bool isHungry;
private bool isAngry;
private bool isSleeping;
public bool IsHungry
{
get
{
return isHungry;
}
}
public bool IsAngry
{
get
{
return isAngry;
}
}
public bool IsSleeping
{
get
{
return isSleeping;
}
}
public Dog()
{
isHungry = false;
isAngry = false;
isSleeping = false;
}
public void Pet()
{
isAngry = false;
}
public void Tease()
{
isAngry = false;
}
public void Feed()
{
isHungry = false;
}
public void Age()
{
isHungry = true;
}
public void GoToSleep()
{
isSleeping = true;
}
public void WakeUp()
{
isSleeping = false;
}
}
[/CODE]
I created buttons.
[CODE]
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public void pictureBox1_Click(object sender, EventArgs e)
{
}
public void buttonPet_Click(object sender, EventArgs e)
{
}
public void buttonTease_Click(object sender, EventArgs e)
{
}
public void buttonFeed_Click(object sender, EventArgs e)
{
}
public void buttonAge_Click(object sender, EventArgs e)
{
}
public void buttonGoToSleep_Click(object sender, EventArgs e)
{
}
public void buttonWakeUp_Click(object sender, EventArgs e)
{
}
}
[/CODE]
I have placed images of dogs in an image list but don't know how to proceed from here. How do I get the button to do what it is supposed to do and show an image? The images are as follows:
angry_dog.bmp
eat_dog.gif
happy_dog.jpg
sleep_dog.jpg
I also wrote the following code but have no clue where to put it. Right now it is in Program.cs under main.
[CODE]
Dog myDog;
myDog = new Dog();
myDog.Pet();
myDog.Tease();
myDog.Feed();
myDog.Age();
myDog.GoToSleep();
myDog.WakeUp();
[/CODE]
Please help.
|
|
|
|
|
apricotsun wrote: public void buttonGoToSleep_Click(object sender, EventArgs e)
{
}
This is an event handler. Assuming that myDog is a member variable ( declared inside a class, not inside any method, and therefore visible to all methods for this instance of this class ), you should do myDog.GoToSleep(); here. I trust you can see how this pattern would apply to your other methods/events.
apricotsun wrote: I have placed images of dogs in an image list but don't know how to proceed from here.
There are a number of controls that will show an image from an image list, they will take the image list and an index into the list. So, if you use such a control, you can just change the index in the control that shows the image, inside those event handlers.
An alternative is to add the images to your resources, and load them from there. Then you can just use a PictureBox and keep changing what image it shows.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Thank you. I will try that.
|
|
|
|
|
Picture box sounds like a great idea. How do I get it to change images when the appropriate button is clicked on?
|
|
|
|
|
Also, where do I declare myDog? I tried declaring it in the Dog class but that did not work. Then I tried declaring it under Main in the Program.cs but that did not work. Then I tried declaring it in the form itself and that did not work. Would I have to create another class for it? I'm sorry for asking so many questions. As I said I'm a newbie and want to learn.
|
|
|
|
|
I am confused. I want Windows to act like this: When the user double clicks the icon in Windows Explorer, it opens up the file my program opens with my program. But how do I set up my program so that this will happen? Thanks in advance.
|
|
|
|
|
C# does Shell, Part 2[^]
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook www.troschuetz.de
|
|
|
|
|
I am trying to add a tool bar using ToolStrip. When I run my application, the tool bar is correctly display, but once I get an OnPaint, I get red box with an X through it where the tool bar should reside. Here is my code.
ToolStrip toolStrip = new ToolStrip();
toolStrip.Parent = this;
ToolStripButton toolStripFileOpen = new ToolStripButton("Open", new Bitmap("openHS.png"), new EventHandler(MenuFileOpenOnClick), "Open");
ToolStripButton toolStripFileSave = new ToolStripButton("Save", new Bitmap("saveHS.png"), new EventHandler(MenuFileSaveOnClick), "Save");
toolStripFileOpen.DisplayStyle = ToolStripItemDisplayStyle.Image;
toolStripFileSave.DisplayStyle = ToolStripItemDisplayStyle.Image;
ToolStripSeparator toolStripSeparator = new ToolStripSeparator();
toolStrip.Items.Add(toolStripFileOpen);
toolStrip.Items.Add(toolStripFileSave);
toolStrip.Items.Add(toolStripSeparator);
Controls.Add(toolStrip);
|
|
|
|
|
Sounds like when you run it, it cannot file those png files. I'd suggest making them resources inside your program, or at least, copy them to the debug/release directories.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
The png files belonged to the project and were made an "Embedded Resource" so I don't think that is the problem. The funny thing is they are displayed fine until I get an OnPaint. I am missing something but I can't find a good reference on ToolStrip.
|
|
|
|
|
Here is an update. I used the auto stuff in .NET for making a form and got the same results. It seems the OnPaint for the client area is being called for the ToolStrip. I just assumed ToolStrip would have it's on OnPaint method.
Here is my entire constructor. I am a fairly new to the C# stuff and this is my learning program. I did not want to use the auto stuff in .NET until I made an application by "hand".
public GLA()
{
Text = "GLA";
programName = Text;
BackColor = SystemColors.Window;
ForeColor = SystemColors.WindowText;
ResizeRedraw = true;
Icon = new Icon(GetType(), "GLA.ico");
// Status bar.
statusBarPanel = new StatusBarPanel();
statusBarPanel.AutoSize = StatusBarPanelAutoSize.Contents;
statusBar = new StatusBar();
statusBar.Parent = this;
statusBar.ShowPanels = true;
statusBar.Panels.Add(statusBarPanel);
// Tool bar.
ToolStrip toolStrip = new ToolStrip();
ToolStripButton toolStripFileOpen = new ToolStripButton("Open", new Bitmap("openHS.png"), new EventHandler(MenuFileOpenOnClick), "Open");
ToolStripButton toolStripFileSave = new ToolStripButton("Save", new Bitmap("saveHS.png"), new EventHandler(MenuFileSaveOnClick), "Save");
toolStripFileOpen.DisplayStyle = ToolStripItemDisplayStyle.Image;
toolStripFileSave.DisplayStyle = ToolStripItemDisplayStyle.Image;
ToolStripSeparator toolStripSeparator = new ToolStripSeparator();
toolStrip.Items.Add(toolStripFileOpen);
toolStrip.Items.Add(toolStripFileSave);
toolStrip.Items.Add(toolStripSeparator);
Controls.Add(toolStrip);
// Menus.
menu = new MenuStrip();
menuFile = new ToolStripMenuItem("&File" );
menuFileOpen = new ToolStripMenuItem("&Open..." , new Bitmap("openHS.png"), new EventHandler(MenuFileOpenOnClick ), Keys.Control | Keys.O);
menuFileSave = new ToolStripMenuItem("&Save" , new Bitmap("saveHS.png"), new EventHandler(MenuFileSaveOnClick ), Keys.Control | Keys.S);
menuFileSaveAs = new ToolStripMenuItem("Sa&ve As..." , null , new EventHandler(MenuFileSaveAsOnClick), Keys.Control | Keys.V);
menuFileExit = new ToolStripMenuItem("&Exit" , null , new EventHandler(MenuFileExitOnClick ), Keys.Control | Keys.E);
menuHelp = new ToolStripMenuItem("&Help" );
menuHelpAbout = new ToolStripMenuItem("&About" , new Bitmap("GLA.ico" ), new EventHandler(MenuHelpAboutOnClick ), Keys.Control | Keys.A);
menuSeparator = new ToolStripSeparator();
menuFileOpen .AutoToolTip = true; menuFileOpen .ToolTipText = "Open a file to edit or view" ;
menuFileSave .AutoToolTip = true; menuFileSave .ToolTipText = "Save the current data set" ;
menuFileSaveAs.AutoToolTip = true; menuFileSaveAs.ToolTipText = "Save data set with a different name";
menuFileExit .AutoToolTip = true; menuFileExit .ToolTipText = "Exit the program" ;
// Add items to the main menu.
menu.Items.Add(menuFile);
menuFile.DropDownItems.Add(menuFileOpen );
menuFile.DropDownItems.Add(menuFileSave );
menuFile.DropDownItems.Add(menuFileSaveAs);
menuFile.DropDownItems.Add(menuSeparator );
menuFile.DropDownItems.Add(menuFileExit );
menu.Items.Add(menuHelp);
menuHelp.DropDownItems.Add(menuHelpAbout );
// Add the list of controls.
Controls.Add(menu);
// Assign the menu to the form.
MainMenuStrip = menu;
// Disable Save and SaveAs since there is no file open.
menuFileSave .Enabled = false;
menuFileSaveAs.Enabled = false;
}
|
|
|
|
|
I have determined the application is using the ToolStrip area as the client area. ToolStrip is calling my OnPaint, OnMouseDown, etc. for the ToolStrip. How do I force it not to do this?
|
|
|
|
|
After going back in Petzold's book, he states that overriding OnPaint also overrides the Controls (ToolStrip, etc.). I read that if one calls Invalidate(false), the child controls will not get the message. Anyway, I made the client area a Panel and made event handlers for mouse moves, paint, etc. This was actually easier to paint to because now I do not have to determine the offsets for the tool bar, status bar, and menu.
Now I need to find an example for StatusStrip instead of using StatusBar.
|
|
|
|
|
Christian, thanks for the advise. If I already have the png files, how to I add the png files as a resource so they are included in the executable? Also, how do I load them into the application?
|
|
|
|
|
Simple question but I guess no one knows the answer.
I finally figured it out.
1) Add a bmp, ico, etc. to your project.
2) Select properties on bmp, ico, etc. and make Build Action - Embedded Resourse
3) Select properties on project, and make Default namespace: - Tools.Test
4) If the code in not in a namespace, then you can loose the Tools prefix.
using System;
using System.Drawing;
using System.Windows.Forms;
namespace Tools
{
class Test : Form
{
public static void Main()
{
Application.Run(new Test());
}
public Test()
{
Text = "Test";
Icon = new Icon(GetType(), "Test.Test.ico");
}
}
}
|
|
|
|
|
I'm trying to implement a software registration in my application. When the user registers, it checks our server for the software license they entered to see if its' valid.
From what I've read on the web, I needed to do this using FTP. I'm still using VS2003 so webclients are not available.
Everything seemed to work fine until one of our customers was behind a well protected firewall. For datasocket transmission I'm using PASV mode, but they still can't register. In fact, they can't even log into our FTP server.
My question is: Is using FTP the best way of sending files and data between server and client with C# .NET 1.0? If so, how would this customer register if behind a firewall. Would they need to have their IT guys allow access to our IP address?
Thanks,
Brian
|
|
|
|
|
Another good idea would be to implement a registration service via http. You have a 99% chance that you clients would have port 80 open. Perhaps in you VS app you can have a link to your server which will allow then to register from there.
|
|
|
|
|
I want to have one thread generate a point location (bouncing ball) and then have a second thread draw the point on a panel. Do I have to use a producer/consumer relationship? What if I wanted to do multiple points...lets say 10?
Bruce Zelenka
|
|
|
|
|
You probably want to make a thread safe collection to hold the balls, and just have your painting thread paint whenever the rest of the app is idle.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Hi,
We have a software product developed in c# (.net 2005). We installed Vista onto a test computer to try it out, and we are experiencing some problems with UI colors. None of us are really up to speed on Vista yet, so we are looking for a little direction.
As an example, the (default) Vista color scheme changes the forecolor of command buttons in our application when executed (IDE not installed on Vista). In Win2K and XP the colors are displayed according to how we have defined them in our code. However, in Vista it appears that text for disabled controls is brighter than for enabled ones. We have a picture box defined with a white background, but for some reason it appears black in Vista.
Perhaps it's something obvious that we're missing, but we have not found anything posted. Can someone offer some advice?
Many thanks in advance!
Ron Birkelbach
Kennebec, Inc.
|
|
|
|
|
If you modified the controls' colours in the designer then there'll be a line inserted in the InitializeComponent method which sets the colour. If you delete these lines the colours will revert to the default and this will hopefully be the correct one for Vista. Alternatively if you're setting colours in code you should look at the SystemColors class.
|
|
|
|
|
hi all,
this is my problem
i used this code
Graphics grfx = this.createGraphics();
grfx.DrawLine(Pens.Black,p1,p2);
in the Mouse_Move EventHandler but it draw alot of lines
so i want to use XOR mode to draw only the last one
thanx in advance
Generator
|
|
|
|
|
Hi!
You could use ControlPaint.DrawReversibleLine() to get something like an "XOR" mode.
But are you sure you know what you're doing?
Usually creating a graphics object in a mouse event handler to do some painting is a bad idea.
Do you dispose of every Graphics object you create? Beginners usually forget about it and then get ressource leaks. And what if the surface you're drawing your lines on gets hidden by another window and redrawn? All your lines will be gone...
Regards,
mav
--
Black holes are the places where God divided by 0...
|
|
|
|
|
hi mav,
actually i didnot draw in mouse move
i put every drawing in OnPaint() but it make some problems
in other parts of code so i decided to draw it in mouse move
(iam just trying to solve my problem so i didnot think in Dispose)
and thanx for remembering me of Dispose as i think u solve to me the problem of my program stop(Resources leak)
thanx again(i will try ControlPaint.DrawReversibleLine())
Generator
|
|
|
|