|
Hi.
I have troubles to change the base type of number, (from integer decimal to hexa. for example).
I have a textbox and a variable with an integer valueand I want to fill the text box with the variable's value but in hexadecimal. How could I do that?.
Thanks.
|
|
|
|
|
|
Hi all,
I am trying to add records to a Access DB. I use the following code to do this. The record gets recorded in the db's but when I read the record back from the database. All fields report nothing. Now heres the clincher. When I go to Access and do a query for that record in Access it still reports nothing even though the record is in table. Now when I cut and paste the record back into same table. wahlah its fine. Am I maybe missing some kind of commit in this code? Any ideas?
<br />
try <br />
{ <br />
<br />
DataSet dsHours = new DataSet(); <br />
System.Data.DataRow drTS; <br />
daHours.TableMappings.Add("Table", "Hours" ); <br />
daHours.Fill(dsHours ,"Hours"); <br />
<br />
drTS = dsHours.Tables["Hours"].NewRow(); <br />
drTS["TSDate"] = dtEndDate.Value; <br />
drTS["EmployeeID"] = tbEmployeeNum.Text.ToString(); <br />
drTS["TSMonReg"] = tbMon.Text.ToString(); <br />
drTS["TSTuesReg"] = tbTues.Text.ToString(); <br />
drTS["TSWedsReg"] = tbWeds.Text.ToString(); <br />
drTS["TSThursReg"] = tbThurs.Text.ToString(); <br />
drTS["TSFriReg"] = tbFri.Text.ToString(); <br />
drTS["TSSatReg"] = tbSat.Text.ToString(); <br />
drTS["TSSunReg"] = tbSun.Text.ToString(); <br />
drTS["TSMonOT"] = tbMonOT.Text.ToString(); <br />
dsHours.Tables["Hours"].Rows.Add(drTS); <br />
<br />
daHours.Update(dsHours); <br />
MessageBox.Show("Record Added Successfully !"); <br />
bUpdateTS.Visible = true; <br />
bAddTS.Visible = false; <br />
} <br />
catch (OleDbException err) <br />
{ <br />
string errorMessage = "Message: " + err.Message + "\n" + <br />
"Source: " + err.Source + "\n" ; <br />
MessageBox.Show(errorMessage,"Error in DataCon"); <br />
} <br />
catch(Exception err) <br />
{ <br />
MessageBox.Show(err.Message,"General Error"); <br />
} <br />
<br />
This is for an insert into the Access DB. I use commandbuilder to build the insert into the Access DB. It automatically generates the insert statement for me. Is it possible to assign my own SQL Insert string to the DataAdapters InsertCommand instead? Or is the one generated by the COmmandbuilder more efficient even though it doesn't work properly? Also how can I check to see what the version is for Jet 4 oledb is? Should I use maybe ODBC connection string to the Access DB instead, maybe more reliable? What do you guys think? How can I tell if I have the latest data drivers for .net?
Thanks,
JJ
|
|
|
|
|
|
|
|
|
|
I'm trying to maje an animation using gif.
I have several frames that I want to save inmy gif file, using the SaveAdd function.
But I cannot find anywhere example or documentation about the gif encoder.
Can someone give my an example of how to do it, or direct me to some example?
I have found only info for Tiff.
|
|
|
|
|
All the classes involved are an abstract implementation, meaning what works for one works for another (the classes used themselves, that is). If you want to know what EncoderParameter s are supported, see this simple console app that I threw together quick:
using System;
using System.Collections;
using System.Drawing;
using System.Drawing.Imaging;
using System.Reflection;
public class Test
{
static void Main(string[] args)
{
string fe = "gif";
if (args.Length > 0) fe = args[0];
ImageCodecInfo[] codecs = ImageCodecInfo.GetImageEncoders();
ImageCodecInfo codec = null;
foreach (ImageCodecInfo ci in codecs)
{
if (ci.FilenameExtension.ToLower().IndexOf(fe.ToLower()) >= 0)
{
codec = ci;
break;
}
}
if (codec == null)
{
Console.Error.WriteLine("No image codec found for extension " + fe);
return;
}
Image img = new Bitmap(1, 1);
EncoderParameters encparams = null;
try
{
encparams = img.GetEncoderParameterList(codec.Clsid);
}
catch (NotImplementedException)
{
Console.Error.WriteLine("No encoder parameters supported for extension " + fe);
return;
}
foreach (EncoderParameter encparam in encparams.Param)
{
string encname = GetEncoderName(encparam.Encoder.Guid);
Console.WriteLine("{0}: {1}", encname, encparam.Type);
}
}
static Hashtable encnames;
static string GetEncoderName(Guid g)
{
if (encnames == null)
{
encnames = new Hashtable();
Type t = typeof(Encoder);
FieldInfo[] fields = t.GetFields(BindingFlags.Public | BindingFlags.Static);
foreach (FieldInfo field in fields)
{
Encoder enc = (Encoder)field.GetValue(null);
encnames[enc.Guid] = field.Name;
}
}
return encnames[g] as string;
}
} If you run this, you'll see that the GIF image encoder doesn't even support any EncoderParameters , so you can just pass null .
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
It doesn't work.
preview.Save(fileName, myImageCodecInfo, myEncoderParameters); // OK
preview.SaveAdd(frame,null); // Wrong parameters used (sorry, the exact error message is in French).
I've tried to use null for myEncoderParameters in the Save, same result
Also same result if I don't use the CodecInfo at all.
The code works with TIFF. Not with gif. Any idea?
|
|
|
|
|
Of course passing null or a null reference results in the same problem - it's the same exact thing!
As I said before, the whole thing is pretty abstract, so you take use the concepts for the TIFF example (wherever you got that) and apply it to saving a frame with a GIF image. The documentation has more information about the EncoderParameter s that are supported by GDI+. The Encoder class has several static fields with various pre-defined Encoder s that you can use in the EncoderParameter s. See the documentation for them in the .NET Framework SDK.
The code I posted shows that the GIF image encoder doesn't support any Encoder s, so i don't know why passing null doesn't work. Google should find some examples if you use the right keywords.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
http://www.dotnet247.com/247reference/msgs/28/140380.aspx
it seems only the TIFF encoder supports multipages...
|
|
|
|
|
I have written the following code that is called from a component's paint method. The problem is, that nothing happens.
THe error codes returned from the drawthemebackground is 0, and the Rectangle method returns 1. Yet nothing happens.
However, when i draw something from the graphics object, retrieved from the same CreateGraphics method of the parent object, it draws ok.
pTHEME = ThemeAPI.OpenThemeData(this.Handle,"Window");<br />
<br />
Graphics clientDC = this.Parent.CreateGraphics(); <br />
IntPtr hdc = clientDC.GetHdc(); <br />
pDC = ThemeAPI.CreateCompatibleDC(hdc);<br />
<br />
Rectangle borderRect = new Rectangle(this.Location, this.Size);<br />
<br />
ThemeAPI.Rect rect = new ThemeAPI.Rect();<br />
rect.left = borderRect.Left - 20;<br />
rect.top = borderRect.Top - 20;<br />
rect.right = borderRect.Right + 20;<br />
rect.bottom = borderRect.Bottom + 20;<br />
<br />
ThemeAPI.Rect clipRect = new ThemeAPI.Rect();<br />
rect.left = 0;<br />
rect.top = 0;<br />
rect.right = 0;<br />
rect.bottom = 0;<br />
<br />
int result;<br />
int state = 1;<br />
for (int part=0; part<20; part++)<br />
{<br />
result = ThemeAPI.DrawThemeBackground(pTHEME,hdc,part,state,ref rect,ref clipRect);<br />
}<br />
<br />
result = ThemeAPI.Rectangle(pDC, borderRect.Left-5,<br />
borderRect.Top-5, borderRect.Right+5, borderRect.Bottom+5);<br />
<br />
<br />
Graphics clientDC2 = this.Parent.CreateGraphics();<br />
Pen RedPen = new Pen(Color.Red, 10);<br />
clientDC2.DrawRectangle(RedPen,borderRect);<br />
Pen GreenPen = new Pen(Color.Green, 5);<br />
clientDC2.DrawEllipse(GreenPen,borderRect);<br />
clientDC2.Dispose();<br />
<br />
clientDC.ReleaseHdc(hdc);
Can anyone tell me why it does not like my device handle? I've tried creating a compatible version, but it still does nothing.
I've followed the instructions to the letter, so i'm baffled. If anyone has any thoughts, they would be appreciated.
Cheers
Cata
|
|
|
|
|
Why are you creating a Graphics object from the parent? Each control when painted has its own device context, so you're actually trying to paint in the parent's device context which probably wouldn't do anything. Get the HDC from the Graphics object in the PaintEventArgs passed to you in OnPaint (or the Paint event if not in a derivative class).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I know the parents device context works. I can draw stuff with it. Just not with P/Invoke.
I've tried using the controls getgraphics, and the event graphics to generate a DC, but the only one that works is the parents.
I've experimented painting with the parents device context. And that works ok for non P/Invoke methods like drawing rectangles.
I can't seem to draw inside the control at all. I've made it, and all it's components transparent as well, to see what happened, and still got nothing.
|
|
|
|
|
When you use the Graphics object from any control, it will work, yes. This is because you're using GDI+. When you start painting with device contexts (which is NOT the same as a Graphics object!), things work a bit differently because you're using the older GDI library. You can read more about these in the Platform SDK.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
your cliprect is empty, hence nothing will be exposed, the behaviour will be different depending whether u use double buffering or not.
top secret
|
|
|
|
|
How can we ShutDown Windows using APIs ? I am sure its possible with APIs. If there is another way to ShutDown Windows using C# code. Then please do tell me.
Cheers
|
|
|
|
|
You can P/Invoke either ExitWindowsEx or InitiateSystemShutdownEx. You can look them both up on MSDN. http://msdn.microsoft.com[^]
RageInTheMachine9532
|
|
|
|
|
İs there anybody can help me about this,i want to open and edit dicom images with c# codes,please help me.
|
|
|
|
|
;P
http://sourceforge.net/projects/dicom-cs/
|
|
|
|
|
Much information and links on DICOM can be found here[^].
If your going to be editing images, you might want to consider downloading the DICOM spec (in PDF form) from that same site.
RageInTheMachine9532
|
|
|
|
|
I am doing my final year project on remote desktop control.So I want to control remotely keyboard and mouse.How can i do this in C#.I know for mouse we can use Cursor.position.x or Cursor.position.y but how to get or set keyboard events?please help me in any way.
mughalali
|
|
|
|
|
mughalali wrote:
I know for mouse we can use Cursor.position.x or Cursor.position.y...
Actually, no you can't. Cursor.Position is defined as a Point , which is a value type. If you set the X and Y properties, you won't change anything because you're changing it on a copy of the Position . You would actually have to do something like this:
Cursor.Position = new Point(x, y); To send key strokes, you can use the SendKeys class, which sends keys to the active window. It's pretty limited, so if you want more control you should P/Invoke native APIs like PostMessage . See the Platform SDK documentation for more details.
Microsoft MVP, Visual C#
My Articles
|
|
|
|