|
How can I make it so that the vertical pointing icons appear in my ListView after the user has clicked on a header to sort it????? I have been trying to figure this out for a bit now and I dont have a clue.
|
|
|
|
|
Hi. I created a dataAdapter and a typed dataset, which refers to a stored procedure that takes an input value. How would I use this dataSet, or fill the dataAdapter, as I dont know how to tell it what the input value must be (which happens to be an int).
|
|
|
|
|
I am writing a function that checks whether the same program already started. In case the same program is lready started, the control will be moved to the opened program, and the program is closed.
PMN
|
|
|
|
|
|
i created a table with 9 columns using datatable and tablestyles.
Also i got a DataRelation.
How can i tell my childcolumn to change if the parentcolumn changes?
e.g. in column "number" is 10 the value,
if I change the value to 17 in parenttable,the value in childttable should also change
|
|
|
|
|
Hey i am using a hashtable, and i am adding my fields collection to it.
when i iterate through them they found to be not in the order in which i added them. how do i maintain the sequence in which the elements are added.
thanks
Cheers,
Venkatraman Kalyanam
Bangalore - India
"Being Excellent is not a skill, it is an attitude"
Reality is an illusion caused by caffeine deficiency(one Microsoft Research scholor)
|
|
|
|
|
You don't. Hashtables do not store the sequence that you added the items.
You should use an arraylist.
|
|
|
|
|
Indeed.
If you want your data to be always sorted, ArrayList is probably better than Hashtable.
If you use Hashtable because most of the times you don't care about sorted data, but
you'd rather have a near-O(1) access time, then Hashtable is better.
Note, however, that you can use an Hashtable and, when needed, sort the values as needed and live happily ever-after.
Frank
|
|
|
|
|
You might consider the System.Collections.Specialized.ListDictionary . It implements the IDictionary interface with a linked list. It would be my guess (just a guess) that the order of addition is maintained. Be aware, according to the documentation, ListDictionary is superior to hashtable performance-wise up to about ten items. If your list is longer, consider another strategy.
α.γεεκ Fortune passes everywhere. Duke Leto Atreides
|
|
|
|
|
For me, the best solution tends to be maintaining two data structures, an array or arraylist with the keys in the desired order, and a hashtable with the key-value pairs.
You could easily devise data structures that combine the two, such as a hashtable where the list of keys is a linked list.
|
|
|
|
|
I have a set of 8 buttons, named "button0, 1, 2,... 7" their text also coresponds with their names, such as "0, 1, 2,... 7".
for each button I have this code..
private void button1_Click(object sender, System.EventArgs e)
{
int nOutNum;
string NUM="1";
nOutNum=short.Parse(NUM, NumberStyles.AllowHexSpecifier);
NTPort.Outport(nAddress, (short)nOutNum);
}
for each button I have string NUM equal what ever the text of the button is, 0-7.
That's kinda' ghetto looking and to manage...
here's the question...
how can I make NUM equal whatever the text of the button says...?
/\ |_ E X E GG
|
|
|
|
|
Hi eggie5,
1. set each button's Tag property to the appropriate number
2. create only one callback method for all button's click event and assign it
3. use the sender object to get the Tag property's value
this.button1.Tag = 1;
this.button2.Tag = 2;
this.button3.Tag = 3;
this.button4.Tag = 4;
this.button5.Tag = 5;
this.button6.Tag = 6;
this.button7.Tag = 7;
this.button0.Click += new System.EventHandler(ClickHandler);
this.button1.Click += new System.EventHandler(ClickHandler);
this.button2.Click += new System.EventHandler(ClickHandler);
this.button3.Click += new System.EventHandler(ClickHandler);
this.button4.Click += new System.EventHandler(ClickHandler);
this.button5.Click += new System.EventHandler(ClickHandler);
this.button6.Click += new System.EventHandler(ClickHandler);
this.button7.Click += new System.EventHandler(ClickHandler);
private void ClickHandler(object sender, EventArgs ea)
{
short nOutNum = (short) ((Control)sender).Tag;
NTPort.Outport(nAddress, (short)nOutNum);
}
Have fun,
Dave
|
|
|
|
|
Thanks man. you rule.
/\ |_ E X E GG
|
|
|
|
|
Hi Guys..
I've been going crazy for two days now, and I feel I'm very close. I've got a 3rd party DLL that returns a HANDLE to a DIB (GDI). I've retrieved the BITMAPINFO structure, created a Bitmap and locked the bits. However, when I try and copy the data in, I always get an unhandled exception. Here's my code:
<br />
IntPtr lpArray = CaptureAndFetch();
IntPtr pDib = GlobalLock(lpArray);<br />
BITMAPINFO pbmi = (BITMAPINFO)Marshal.PtrToStructure(pDib, typeof(BITMAPINFO));
<br />
bitmap = new Bitmap(pbmi.bmiHeader.biWidth, pbmi.bmiHeader.biHeight, PixelFormat.Format24bppRgb);<br />
<br />
BitmapData bmData; <br />
Rectangle rect = new Rectangle(0, 0, pbmi.bmiHeader.biWidth, pbmi.bmiHeader.biHeight );<br />
bmData = bitmap.LockBits(rect, ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb );<br />
<br />
GCHandle hSrc = GCHandle.Alloc(pDib, GCHandleType.Pinned );
IntPtr pBits = hSrc.AddrOfPinnedObject();<br />
<br />
Int32 pAddress = (Int32)pBits;<br />
pAddress += Marshal.SizeOf(pbmi);<br />
pBits = (IntPtr)pAddress;<br />
<br />
GCHandle hDest = GCHandle.Alloc(bmData.Scan0, GCHandleType.Pinned);<br />
IntPtr pDest = hDest.AddrOfPinnedObject();<br />
<br />
int length = pbmi.bmiHeader.biHeight * bmData.Stride;<br />
<br />
byte databyte;<br />
for (int idx = 0; idx <= length; idx++)<br />
{<br />
databyte = Marshal.ReadByte(pBits, idx);
Marshal.WriteByte(pDest, idx, databyte);<br />
}<br />
<br />
bitmap.UnlockBits( bmData );<br />
hSrc.Free();<br />
hDest.Free();<br />
GlobalUnlock(lpArray);<br />
|
|
|
|
|
I don't think that explicit play with things like "GCHandle" are about to work well anyway. My recommendation is to write this code using C/C++ in a dll, then use P/Invoke to call the function from C#.
Of course, using MC++ is even better. If you can afford it.
|
|
|
|
|
There's no reason why it wouldn't work in C#. But I do recommend he use pointers to work with the bitmap bits.
"Blessed are the peacemakers, for they shall be called sons of God." - Jesus
"You must be the change you wish to see in the world." - Mahatma Gandhi
|
|
|
|
|
I'm not sure exactly what causes this, I did notice that you're not skipping the word alignment bytes. This rarely causes a problem, though, even though it's not recommended.
Also, what method are you using in the C++ DLL to create the DIB?
Also, have you considered using pointers, rather than Marshall.ReadByte/WriteByte?
"Blessed are the peacemakers, for they shall be called sons of God." - Jesus
"You must be the change you wish to see in the world." - Mahatma Gandhi
|
|
|
|
|
Thanks so much for your help!
On the brink of insanity, I stumbled across a solution, from who else but a CodeProject contributor, Thomas. He wrote a Twain interface for .NET that can be found here:
http://www.codeproject.com/dotnet/twaindotnet.asp. His class contains code for extracting a Bitmap from a HBITMAP.
This has certainly been a tough intro to C# for me! I find it strange that the GDI+ library has a FromBITMAPINFO() function that takes a pointer to a BITMAPINFO structure and the bits and returns a new Bitmap object. However, this is not exposed in C#.
|
|
|
|
|
Hello,
I wanted to know if you think that it is possible to write a control based on RichTextBox so that it can support the page view (like word)?
Or it is better to write this component basing it on Control?
Or do you have another option?
Thanks a lot for your answers..
Kerad
|
|
|
|
|
|
Can someone show me how to draw a raised rectangle on a form using GDI+ ?
When the user click the rectangle, then it must be lower.
KeyDown = lower;
KeyUp = raised;
Thanks
|
|
|
|
|
I need something like this:
System.Drawing.Graphics formGraphics = null;
System.Drawing.Pen myPen;
formGraphics = pictureBox1.CreateGraphics();
myPen = new System.Drawing.Pen(System.Drawing.Color.Black,1);
formGraphics.DrawLine(myPen, 5, 5, 105, 5);
formGraphics.DrawLine(myPen, 15, 35, 95, 35);
formGraphics.DrawLine(myPen, 5, 5, 15, 35);
formGraphics.DrawLine(myPen, 105, 5, 95, 35);
SolidBrush darkGrayBrush = new SolidBrush(Color.Gray);
Point point1 = new Point(5, 5);
Point point2 = new Point(105, 5);
Point point3 = new Point(15, 35);
Point point4 = new Point(95, 35);
Point point5 = new Point(5, 5);
Point point6 = new Point(15, 35);
Point point7 = new Point(105, 5);
Point point8 = new Point(95, 35);
Point[] curvePoints = new Point[]
{
point1,
point2,
point3,
point4,
point5,
point6,
point7,
point8
};
formGraphics.FillPolygon(darkGrayBrush, curvePoints);
but just raised, lower and clickable.
How?
|
|
|
|
|
So you need a rounded-edge rectangle? Right now I have the code for a raised, sunken, etched, or bump border for a rectangle, but not for a rounded-edge rectangle.
"Blessed are the peacemakers, for they shall be called sons of God." - Jesus
"You must be the change you wish to see in the world." - Mahatma Gandhi
|
|
|
|
|
jdunlap:
Can you show me the code for a raised / sunken rectangle?
|
|
|
|
|
If you just need sunken and raised borders, you can use .NET's built-in implementation - System.Windows.Forms.ControlPaint.DrawBorder:
But the ControlPaint.DrawBorder method doesn't do etched and bump borders, where as the code below does:
public enum BorderStyle
{
Raised,Sunken,Etched,Bump
};
public static void DrawBorder(Graphics g,
Rectangle rect,
BorderStyle border,
Color color)
{
BorderStyle inner=BorderStyle.Raised;
BorderStyle outer=BorderStyle.Raised;
switch(border)
{
case BorderStyle.Raised:
inner=BorderStyle.Raised;
outer=BorderStyle.Raised;
break;
case BorderStyle.Sunken:
inner=BorderStyle.Sunken;
outer=BorderStyle.Sunken;
break;
case BorderStyle.Etched:
inner=BorderStyle.Raised;
outer=BorderStyle.Sunken;
break;
case BorderStyle.Bump:
inner=BorderStyle.Sunken;
outer=BorderStyle.Raised;
break;
}
DrawThinBorder(g,rect,outer,color,inner==outer);
rect.Offset(1,1);
rect.Width-=2;rect.Height-=2;
DrawThinBorder(g,rect,inner,color,false);
}
public static void DrawThinBorder(Graphics g,
Rectangle rect,
BorderStyle border,
Color color)
{DrawThinBorder(g,rect,border,color,false);}
public static void DrawThinBorder(Graphics g,
Rectangle rect,
BorderStyle border,
Color color,
bool outer)
{
if(border==BorderStyle.Raised)
{
DrawUpperCorner(g,rect,new Pen((outer?ColorHelper.LightenColor(color,1):color)));
DrawLowerCorner(g,rect,new Pen(ColorHelper.DarkenColor(color,(outer?3:1))));
}else
{
DrawUpperCorner(g,rect,new Pen(ColorHelper.DarkenColor(color,(outer?1:2))));
DrawLowerCorner(g,rect,new Pen((outer?ColorHelper.LightenColor(color,1):color)));
}
}
public static void DrawUpperCorner(Graphics g, Rectangle rect, Pen pen)
{
g.DrawLine(pen,rect.X, rect.Y,rect.X,rect.Y+rect.Height);
g.DrawLine(pen,rect.X, rect.Y,rect.X+rect.Width,rect.Y);
}
public static void DrawLowerCorner(Graphics g, Rectangle rect, Pen pen)
{
g.DrawLine(pen,rect.X+rect.Width, rect.Y,rect.X+rect.Width,rect.Y+rect.Height);
g.DrawLine(pen,rect.X, rect.Y+rect.Height,rect.X+rect.Width,rect.Y+rect.Height);
}
BTW, the LightenColor and DarkenColor methods return a lighter or darker version of the color passed in. I can send you the code for them if you like, but I don't want to post it here, as it's too long.
"Blessed are the peacemakers, for they shall be called sons of God." - Jesus
"You must be the change you wish to see in the world." - Mahatma Gandhi
|
|
|
|
|