|
In the closing event if you set e.Cancel = true; then the form will not close.
My current favourite word is: Nipple!
-SK Genius
Game Programming articles start - here[ ^]-
|
|
|
|
|
Just Do This !!!
private void Form1_FormClosing(object sender, FormClosingEventArgs e)<br />
{<br />
if (textBox1.Text == "")<br />
{<br />
MessageBox.Show("Please Fill Details");<br />
e.Cancel = true;<br />
}<br />
else<br />
{<br />
MessageBox.Show("Thanks You !!!");<br />
}<br />
}
|
|
|
|
|
Check out the ErrorProvider[^] class/component.
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Expect everything to be hard and then enjoy the things that come easy. (code-frog)
|
|
|
|
|
Hi,
I am trying to change the background color of the listview items depending on their text.
The problem is, the items don't keep their background color after every repaint. I tried the refresh() and update() function to make the items keep their color, but that didn't work.
I don't see any other function or property which might fix this problem i'm having.
I have heard about 'onwerdraw' but i have no idea how to use that, googeling this up hasn't showed a few interesting examples or if it fixes this problem for that matter.
If anyone has a success story about 'onwerdraw' with an example code, i'd really appreciate it. Or a suggestion about how to fix this issue.
Thanks in advance!
|
|
|
|
|
|
Hi,
Is there no alternative than to use ownerdraw?
It would be nice to catch the repaint event and put there the coloring stuff.
|
|
|
|
|
Setting BackColor for each item is another way (which you have used). I made a little test and forcing refresh didn't make the items to loose their color. In what situation you face the problem?
Test was (two buttons on a form and a listview):
private void button1_Click(object sender, EventArgs e) {
ListViewItem lvItem;
for (int i = 0; i < 10; i++) {
lvItem = new ListViewItem();
lvItem.Text = lvItem.GetHashCode().ToString();
lvItem.BackColor = Color.LightBlue;
listView1.Items.Add(lvItem);
}
lvItem = new ListViewItem();
lvItem.Text = lvItem.GetHashCode().ToString();
lvItem.BackColor = Color.Red;
listView1.Items.Add(lvItem);
}
private void button2_Click(object sender, EventArgs e) {
this.Refresh();
}
|
|
|
|
|
Hi,
I'll try to describe the situation.
The items in the listview control can have several states. The states are defined in the 3rd column.
Depending on that status text, i am giving the items a color. They do get the color but as soon as i select an item, the color is gone. And any other event on the listview control is making this happen too.
I am looping through a switch statement and assigning there the back color for the items. After that, i refresh the listview control.
|
|
|
|
|
I tested clicking and refreshing with the code I posted and no problems. Test case was:
private void listView1_ItemSelectionChanged(object sender, ListViewItemSelectionChangedEventArgs e) {
foreach (ListViewItem lvItem in listView1.Items) {
lvItem.BackColor = Color.Purple;
}
listView1.Refresh();
}
If I understood correctly, this would be similar to your case
So I suspect that the problem is somehow in the loop where you define (and possibly reset) the colors for each item.
|
|
|
|
|
Hi,
I forgot to mention that i have to use delegates to access the listview control. I only assign the color at one place.
That shouldn't be the problem right?
|
|
|
|
|
Delegates themselves are not the problem. However if you receive events in a wrong order, that could cause the problem (event to set colors before event to reset colors etc).
Use debugger to confirm that your code is run in desired order. You could also use conditional breakpoints so that whenever a listviewitems background color changes, the debugger breaks. That could give you idea what's going wrong.
|
|
|
|
|
Hi,
The coloring of the items happens in another class. The listview control is passed by ref to that other class.
It shouldn't be a problem if i don't color the items in the Form class right?
The delegates run in the right order.
|
|
|
|
|
No, that isn't a problem as long as you work with the original ListViewItems (i.e. don't make copies).
Did you try to break on refresh or use conditional breakpoints. I believe they would clarify this greatly.
|
|
|
|
|
Hi,
I did both, the colors really get assigned. But they are just not visible. If i minimize the window and bringing it back to front, i can see the colors but disappear really fast again.
[EDIT 12:33h]
Hi,
It seems that i managed to fix this a bit. I created a paint event from the Form.
I do all the coloring stuff in there now. It seems that it keeps the colors, but if i select an item, it loses its color.
If i use the selectedIndexChanged event for the listview control, and i select an item, i lose all the colors on every item.
I need a way to call the Paint event inside the selectedIndexChanged event of the listview control. This might do the trick.
I tried this: this.frmMain_Paint(this.listviewcontrol, null);
But that didn't work...
[/Edit]
modified on Sunday, August 31, 2008 6:33 AM
|
|
|
|
|
For some reason the coloring is reset after you assign the color. Did the example I posted work corectly? If it did, I suggest that you comment code out so that you get painting correclty and then try to bring back code only in small pieces.
Also check the form's DoubleBuffered property. I believe it should be false.
|
|
|
|
|
i have this non rectangular window (spline-shaped) :
using System;
using System.Windows.Forms;
using System.Drawing;
using System.Drawing.Drawing2D;
namespace Guitar
{
class GuitarForm : Form
{
Bitmap bmp;
GuitarForm()
{
bmp = new Bitmap("C:\\ok.jpg");
GraphicsPath gp = new GraphicsPath();
Point[] curves = new Point[]{
new Point(93,99), new Point(200, 55),
new Point(328, 128),new Point(450,100),new Point(560,200),
};
gp.AddCurve(curves);
gp.AddLine(560,200, 560, 500);
gp.AddLine(560, 500, 93, 500);
gp.AddLine(93, 500, 93, 99);
gp.CloseFigure();
this.Region = new Region(gp);
}
protected override void OnPaint(PaintEventArgs ea)
{
base.OnPaint(ea);
Graphics g = ea.Graphics;
g.DrawImage(bmp, new Point(0, 0));
Rectangle scaled = new Rectangle(20, 20, 60, 60);
g.DrawImage(bmp,scaled);
g.DrawRectangle(Pens.Red, scaled);
Point[] pGram = new Point[]{
new Point(50, 10),
new Point(100, 30),
new Point(20, 100),
};
g.DrawImage(bmp, pGram);
}
public static void Main()
{
Application.Run(new GuitarForm());
}
private void InitializeComponent()
{
this.SuspendLayout();
this.ClientSize = new System.Drawing.Size(560, 560);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
this.Name = "GuitarForm";
this.ResumeLayout(false);
}
}}
the problem is that when i run it, only one part of the window appears and i have to drag to brders in order to see the whole shape . Is there any way it can run all-ready sized the way i want it ?
|
|
|
|
|
Could it be something as simple as this.Size = ...?
Mark Brock
"We're definitely not going to make a G or a PG version of this. It's not PillowfightCraft." -- Chris Metzen
Click here to view my blog
|
|
|
|
|
Simple things always get me Thank you , Mark!
|
|
|
|
|
Hi ,
Is there any event for both the textchange and selectindexchange in combobox
{that event must fire when we made any change in the text as well as selectindexchange
|
|
|
|
|
There isn't, but just use both events and keep track of them yourself, like:
bool textChanged = false;
bool indexChanged = false;
void TextChanged()
{
if(!indexChanged)
textChanged = true;
else {
indexChanged = false
EventsFired();
}
}
void IndexChanged()
{
if(!textChanged)
indexChanged = true;
else {
textChanged = false
EventsFired();
}
}
void EventsFired()
{
}
My current favourite word is: I'm starting to run out of fav. words!
-SK Genius
Game Programming articles start - here[ ^]-
|
|
|
|
|
there are no events for handle both events,
specify event handler like this:
this.comboBox1.SelectedIndexChanged += new System.EventHandler(this.comboBox1_SelectedIndexChanged);
this.comboBox1.TextChanged += new System.EventHandler(this.comboBox1_SelectedIndexChanged);
then you perfom actions in
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
}
this done because both events are apply from System.EventHandler
dhaim
programming is a hobby that make some money as side effect
|
|
|
|
|
how can i create new stencil bar in ms visio using c#.net and save, open, new file
tahir
|
|
|
|
|
|
I have a pre-printed invoices on dot matrix and i want to print the customers' invoices on it...
which method is best? printing to specefic point or use RDLC?
|
|
|
|
|
Hi,
You don't need a complicated algo. here, RDLC is more than enough.
good luck,
|
|
|
|