|
Hey thanks for the reply.
I will try this. Seems I need to get my concepts on events and delegates proper.
Best Regards,
Sid
|
|
|
|
|
hello
Trying to write simpler code... how can I reduce the number of the else-if blocks below?
<br />
if (o is DictionaryEntry)<br />
{<br />
DictionaryEntry oEntry = (DictionaryEntry)o;<br />
object oKey = oEntry.Key;<br />
object oValue = oEntry.Value;<br />
<br />
lstAnotherCollection.Add(oKey, oValue);<br />
... more ...<br />
}<br />
else if (o is KeyValuePair<string, System.Drawing.Bitmap>)<br />
{<br />
<br />
KeyValuePair<string, System.Drawing.Bitmap> oEntry = (KeyValuePair<string, System.Drawing.Bitmap>)o;<br />
string oKey = oEntry.Key;<br />
System.Drawing.Bitmap oValue = oEntry.Value;<br />
<br />
lstAnotherCollection.Add(oKey, oValue);<br />
... more ...<br />
}<br />
... many more else-if blocks ...<br />
I suppose I cannot cast KeyValuePair<X,Y> into KeyValuePair<Object, Object> ... because it defeats purpose of Generics in the first place?
Thanks
dev
modified on Sunday, June 21, 2009 6:54 AM
|
|
|
|
|
I'd say you potenially have bigger problems that sorting out a bunch of if/else blocks.
How come you get to this code? Why can o end up being so many different things? There isn't event a common base class to tie it all together.
Excessive casting is a known "code smell" that indicates you are using the wrong types or the types are incorrectly defined.
|
|
|
|
|
it came from code generator code which uses reflection to examine object properties and wrap interceptors... etc. Kind of ugly.
Thanks
dev
|
|
|
|
|
H! All
I have a problem regarding window service. When I tried to start the service from the Services, it gives me an error, "Error 1053: The service did not respond to the start or control request in a timely fashion"..
The code uses System.Threading not System.Timer..i tried to put an additional code to produce a log file so that i can see what is happening while starting in the services.., it executed the routine..from OnStart it calls a function and inside the function..it loops continuously..then i think it was five loops when the error showed up..it didnt pass to the OnStop method..
Another thing I am confused is that i can run or double click the EXE in the debug folder manually and it is running successfully. It seems that I am running an ordinary EXE not a windows service EXE..
BTW, this was built in C#.NET..
Anyone who knows this problem..Please help this is urgent..
Thanks in advance..Regards
|
|
|
|
|
Hello,
I have a SQL query,and i want to check if i get a information from the query,BUT not to show the result for user.
I'm using on DataSet/DataTable.
Someone know how i do that?
thanks.
|
|
|
|
|
If the dataset has tables with rows, then your query returned some values from database. You can check this right after you execute the SQL command.
जय हिंद
|
|
|
|
|
Like This?
That not work.
int CheckValue=da.Fill(ds);<br />
if (CheckValue ==0)<br />
{<br />
cb1.Checked = false;<br />
<br />
}<br />
else<br />
{<br />
cb1.Checked = true;<br />
}
|
|
|
|
|
Wow. Read the documentation instead of wildly guessing. You can call ExecuteNonQuery if you wrote your own SQL code, and if your SQL returns a single result.
Christian Graus
Driven to the arms of OSX by Vista.
"! i don't exactly like or do programming and it only gives me a headache." - spotted in VB forums.
I can do things with my brain that I can't even google. I can flex the front part of my brain instantly anytime I want. It can be exhausting and it even causes me vision problems for some reason. - CaptainSeeSharp
|
|
|
|
|
I cant not.
Giva example if you cant.
thanks.
|
|
|
|
|
You saw that reply? He cannot read the docs. How possibly can you deal with an idiot of this order?! Morons like this are the reason why I asked Chris to appoint a moderator or two for each forum.
I've voted to remove his message. I'll remember never ever to attempt to help him.
It is a crappy thing, but it's life -^ Carlo Pallini
|
|
|
|
|
<sarcasm>
With respects sir, he clearly said "cant not", which is a double negative. That clearly means he can.
Some people...
</sarcasm>
|
|
|
|
|
Hey everyone,
I dont remember what I did but when building my solution I get this error:
The type name 'BUDGETLINESDataTable' does not exist in the type
'myNameSpace.ds_FINANCETableAdapters.ds_FINANCE'
C:\MyProjectPath\ds_FINANCE.Designer.cs
along with several similar errors all pointing to the dataset designer file.
Any hint/shared experience would be appreciated.
All generalizations are wrong, including this one!
(\ /)
(O.o)
(><)
modified on Sunday, June 21, 2009 5:08 AM
|
|
|
|
|
Check you namespaces.
Also your declaration (public/internal/private) can screw it up as well.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Thanks Holmes, I just figured out that I accidently double clicked on the dataset and believe it or not, my whole problem was just because of the empty class created when the dataset was double clicked! I hate typed datasets!
All generalizations are wrong, including this one!
(\ /)
(O.o)
(><)
|
|
|
|
|
Hi,
I have a form that is designed by GDI+, it has some buttons(images)
I want to change the button when the mouse is over the button
so I handled the MouseMove event with the OnMouseMove and I calculated if the mouse is in the button region , after that if it was, I call the method Invalidate() so that the button should be repainted but the problem is that the Program runs very slowly, and you can see the mouse movement in slow motion, when I comment the Invaliate() method in the code, everything is good, I also checked the code with an empty method of OnPaint() so that the problem is not because of OnPaint() but Invalidate()
by the way i am using the Double Buffred Form
I am confused
somebody help me
thank you
P.S:
here is the whole code:
From1.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace paintImage
{
enum ButtonState
{
NotSelected,
Blue,
Green
}
public partial class Form1 : Form
{
ButtonState Language = ButtonState.NotSelected;
private bool MouseOutLanguageTraining = false;
private bool LanguageTraining = false;
private bool MouseOnLangugeTraining = false;
Rectangle LanguageButtonPosition = new Rectangle(774, 617, 218, 42);
readonly Image piccy;
readonly Image ButtonSelectedBlue;
readonly Image ButtonSelectedGreen;
readonly Image ButtonNotSelected;
private readonly Point[] piccyBounds;
private readonly Point[] LanguageButtonBounds;
public Form1()
{
InitializeComponent();
piccy = Image.FromFile(@"C:\pics\page12.png");
ButtonNotSelected = Image.FromFile(@"C:\Pics\Button Not Selected.png");
ButtonSelectedBlue = Image.FromFile(@"C:\pics\Button Selected Blue.png");
ButtonSelectedGreen = Image.FromFile(@"C:\pics\Button Selected Green.png");
AutoScrollMinSize = piccy.Size;
piccyBounds = new Point[3];
LanguageButtonBounds = new Point[3];
const int resolutionX = 1024;
const int resolutionY = 768;
piccyBounds[0] = new Point(0, 0);
piccyBounds[1] = new Point(resolutionX, 0);
piccyBounds[2] = new Point(0, resolutionY);
LanguageButtonBounds[0] = new Point(744, 617);
LanguageButtonBounds[1] = new Point(992, 617);
LanguageButtonBounds[2] = new Point(744, 659);
}
protected override void OnPaint(PaintEventArgs e)
{
Graphics dc = e.Graphics;
base.OnPaint(e);
dc.DrawImage(piccy, piccyBounds);
if (LanguageTraining && (Language != ButtonState.Blue))
{
dc.DrawImage(ButtonSelectedBlue, LanguageButtonBounds);
LanguageTraining = false;
}
else if (MouseOnLangugeTraining && (Language != ButtonState.Green))
{
dc.DrawImage(ButtonSelectedGreen, LanguageButtonBounds);
MouseOnLangugeTraining = false;
}
else if (MouseOutLanguageTraining && (Language != ButtonState.NotSelected))
{
dc.DrawImage(ButtonNotSelected, LanguageButtonBounds);
MouseOutLanguageTraining = false;
}
}
protected override void OnKeyUp(KeyEventArgs e)
{
base.OnKeyUp(e);
if (e.KeyCode == Keys.Escape)
this.Close();
}
protected override void OnMouseClick(MouseEventArgs e)
{
base.OnMouseClick(e);
Point mouseLocation = Control.MousePosition;
if (mouseLocation.X > 755 && mouseLocation.X < 992 && mouseLocation.Y > 625 && mouseLocation.Y < 659)
{
Invalidate();
LanguageTraining = true;
}
}
protected override void OnMouseMove(MouseEventArgs e)
{
base.OnMouseMove(e);
Point mouseLocation = Control.MousePosition;
if (mouseLocation.X > 755 && mouseLocation.X < 992 && mouseLocation.Y > 625 && mouseLocation.Y < 659)
{
MouseOnLangugeTraining = true;
Invalidate();
}
else if (mouseLocation.X < 755 || mouseLocation.X > 992 || mouseLocation.Y < 625 || mouseLocation.Y > 659)
{
MouseOutLanguageTraining = true;
Invalidate(LanguageButtonPosition);
}
}
private void Form1_Load(object sender, EventArgs e)
{
}
}
}
From1.designer.cs
using System.Drawing;
namespace paintImage
{
partial class Form1
{
private System.ComponentModel.IContainer components = null;
protected override void Dispose(bool disposing)
{
piccy.Dispose();
ButtonSelectedBlue.Dispose();
ButtonNotSelected.Dispose();
ButtonSelectedGreen.Dispose();
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
private void InitializeComponent()
{
this.SuspendLayout();
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.BackColor = System.Drawing.Color.Silver;
this.ClientSize = new System.Drawing.Size(1024, 768);
this.DoubleBuffered = true;
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
this.Name = "Form1";
this.StartPosition = System.Windows.Forms.FormStartPosition.Manual;
this.Text = "Form1";
this.TransparencyKey = System.Drawing.Color.Transparent;
this.Load += new System.EventHandler(this.Form1_Load);
this.ResumeLayout(false);
}
#endregion
}
}
|
|
|
|
|
This looks right to me. Of course, the mouse move is going to keep firing paint messages, it probably makes more sense to only fire the invalidate when the state changes.
Christian Graus
Driven to the arms of OSX by Vista.
"! i don't exactly like or do programming and it only gives me a headache." - spotted in VB forums.
I can do things with my brain that I can't even google. I can flex the front part of my brain instantly anytime I want. It can be exhausting and it even causes me vision problems for some reason. - CaptainSeeSharp
|
|
|
|
|
To add to what Chris said, it is probably that you are continually firing Paint messages - why not use MouseEnter and MouseLeave to handle the re-paint? That way, you don't recalculate on every mouse move, and you only fire the Paint when the image should be changing.
BTW: it is not good practice to use absolute numbers for mouse position checking - why not use the position of the button instead?
No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced.
This message is made of fully recyclable Zeros and Ones
|
|
|
|
|
Hi,
Sorry this is gonna sound stupid I expect but here goes
Using
m_AutoCompleteStringCollection = new AutoCompleteStringCollection();
textBoxName.AutoCompleteMode = AutoCompleteMode.Suggest;
textBoxName.AutoCompleteSource = AutoCompleteSource.CustomSource;
textBoxName.AutoCompleteCustomSource = m_AutoCompleteStringCollection;
How, without a mouse, do you select an item for an autocomplete textbox? I have tried key down on the keyboard but that just makes a selection of the first item. I want the user to be able to select any item or type their one choice. This is going to be used as a login where the name can be a known name or a visitor.
Thanks,
Iain
|
|
|
|
|
Down arrow works fine for me. Set the focus to the item to be selected and press enter to select.
जय हिंद
|
|
|
|
|
Yes you are correct.
It appears that calling _TextChanged everytime resets the focus
E.G.
private void textBoxFirstName_TextChanged(object sender, EventArgs e)
{
if (textBoxName.Text.Length > 4)
{
getAutoCompleteSuggestions();
}
}
I have changed it to
if (textBoxName.Text.Length == 4)
To solve this
It does seem to crash a lot too in debug but I will save that for another day
|
|
|
|
|
Is there any specific need to display the autocomplete suggestions only after 4 characters?
जय हिंद
|
|
|
|
|
It was to keep the selection down to something reasonable. All works now thanks for your help.
|
|
|
|
|
I'm using the propertygrid control to display a small class (the class represents program settings) which contains a System.Drawing.Color, and some other properties.
When you click the dropdown next to the color and click a color... everything works fine.
The problem is if the user uses the Up and Down keyboard keys to change the color. When they do this the little color preview square next to the name of the color does not update until the Enter key is pressed.
I tried just using SendKeys to send Enter when the PropertyValueChanged event fires but unfortunately the control looses focus of the selected property.. which is exactly what happens when the enter key is pressed normally. But it's unnatural because your pressing the down and up keys to scroll through the colors... so ya Enter-key-sending is not the way to go.
Is their anyway to force that little color preview box to change to match the color name next to it
|
|
|
|
|
I sent the Tab key as well after enter and it worked fine for me. There might be a decent way to achieve this that I am not aware of.
This way:
SendKeys.SendWait("~");
SendKeys.SendWait("{TAB}");
जय हिंद
|
|
|
|