|
I wish to know why OpenFile and SaveFile dialogs change the current directory.
And if there si a way to prevent this, or shoud I use the following methond : Directory.SetCurrentDirectory( path );
This is what I curently use, and wanted to know if there is some other way.
Lazar Mihai
|
|
|
|
|
That's how they are expected to behave. Instead of using CurrentDirectory, you can try using System.AppDomain.CurrentDomain.ApplicationDirectory or something similar.
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
Your code really shouldn't be depending on the current directory anyway. The general rule-of-thumb in programming is assume nothing!. What this means is you never assume that the file you want to access is in the current directory. Always use fully qualified path names and not just a filename when doing any kind of file access.
This also has other benefits. Say you put up a OpenFileDialog that changed the current directory. After the user picks a file, you try and put the current directory back to what it was. But, your code crashes, for whatever reason, before that can happen! The function ends up returning as failed, but not having restored the current directory. Now what? Your next file access is assuming (there's that word again ) the current directory is correct when it's not, and your app ends up crashing a second time, then a third, forth, fifth, ...
Write your code so it defends itself against itself. Never assume anything is what you expect it to be.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
-- modified at 16:07 Monday 12th September, 2005
|
|
|
|
|
Use this:
<br />
System.Windows.Forms.OpenFileDialog dlgOpenFile = new System.Windows.Forms.OpenFileDialog();<br />
...<br />
dlgOpenFile.RestoreDirectory = true;<br />
DialogResult res = dlgOpenFile.ShowDialog();<br />
But listen to dave's answer, he is totaly right about assuming paths.
|
|
|
|
|
Hey,
Can anyone help me migrating the following struct to C# ? The problem is, that I don`t know how to migrate the union section inside of the struct.
<br />
typedef struct _IMAGE_SECTION_HEADER { BYTE Name[IMAGE_SIZEOF_SHORT_NAME]; union { DWORD PhysicalAddress; DWORD VirtualSize; } Misc; DWORD VirtualAddress; DWORD SizeOfRawData; DWORD PointerToRawData; DWORD PointerToRelocations; DWORD PointerToLinenumbers; WORD NumberOfRelocations; WORD NumberOfLinenumbers; DWORD Characteristics;<br />
} IMAGE_SECTION_HEADER, *PIMAGE_SECTION_HEADER;<br />
Thanks,
Tom
|
|
|
|
|
Tom,
You would do this
[StructLayout(LayoutKind.Explicit)]<br />
public struct _IMAGE_SECTION_HEADER<br />
{<br />
[FieldOffset(0)]<br />
[MarshalAs(UnmanagedType.ByValArray, SizeConst = IMAGE_SIZEOF_SHORT_NAME)]<br />
public byte[] Name;<br />
<br />
[FieldOffset(IMAGE_SIZEOF_SHORT_NAME)]<br />
public int PhysicalAddress;<br />
<br />
[FieldOffset(IMAGE_SIZEOF_SHORT_NAME)]<br />
public int VirtualSize;<br />
<br />
...<br />
<br />
}
You basically put the members of the union at the same offset in the structure.
I hope this helps.
Human beings were not meant to sit in little cubicles staring at computer screens all day, filling out useless forms and listening to eight different bosses drone on about about mission statements. -- Peter Gibbons
|
|
|
|
|
|
sahithya harsha wrote:
STEGANOGRAPHY USING AUDIO FORMAT
sahithya harsha wrote:
i don hav enough idea in c# and am doing self study now.
sahithya harsha wrote:
having my review in two days i gotto show somethng
TWO DAYS?! If you have very little experience in C#, you're going to find this project impossible in the time frame you have. You have to be comfortable with the language before you start a project of this complexity.
You have such a limited time to learn the language, the data formats for any audio file format, what is acceptable to do in that format and what is not, the implementation in code of your algorithms, ..., the only things your going to show at this review is how you've learned how to bite off more that you can chew and what the consequences are.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
|
Let me get this straight. You got the code for this off of this site. You have one month before you have to turn it in. The code you have is part of a 15 part series of articles on stenography. Your best source for information about the code is Corinna John. Afterall, she wrote it.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
hi
i need urhent response
Is there any other way to get HTTP Headers in C# by not using HttpWebRequest and Response Calssess i mean through xml or sockets
if yes
please tell me with code or refrence to code
Thanks
in Advacne
TaRiQ
|
|
|
|
|
What's wrong with a WebRequest?
---
b { font-weight: normal; }
|
|
|
|
|
i m preparing a Request using WebRequest but cant find proper response
thats why i want to use another way to get the response
please tell me in deatail
Thanks
Tariq
TaRiQ
|
|
|
|
|
Hi all !
I have built a .dll in VC++. Now I continute develope it in C#. So I reused dll in C#. But when I using Thread that used this dll, I allway meet a problem : Only Thread using dll in a time. How to using dll for all Thread. Pls help me!
Thank alots !
|
|
|
|
|
Hi,
Lots of code around for capturing a window. But they all suffer from one deficiency.
If another window overlaps the one being captured it becomes part of the capture.
Is there a way to capture a window without bringing to the front of the desktop first (i.e. not using BringWindowToTop)?
Thank you, Jesper
|
|
|
|
|
Create a bitmap or metafile DC and send a WM_PRINT message to the window.
This way, you're not capturing the screen image, you're telling the window to draw itself on your bitmap.
The problem with this approach is that not all windows honor the WM_PRINT message. The .NET framework have a few controls that simply don't draw themselves when you send a WM_PRINT.
I see dead pixels
Yes, even I am blogging now!
|
|
|
|
|
string sInsert = "insert into temp11 values ('This is my test data's ')";<br />
SqlConnection sqlcon = new SqlConnection(ConfigurationSettings.AppSettings["DBConnection"]);<br />
sqlcon.Open();<br />
SqlCommand objcmd = new SqlCommand(sInsert,sqlcon);<br />
objcmd.ExecuteNonQuery();
IT failed becuase there is an "'" inside the text.
I tried to used
sInsert = sInsert.Replace("'","''"); but still failed.
|
|
|
|
|
Try
string sInsert = "insert into temp11 values ('This is my test data''s ')";
|
|
|
|
|
You should use parameterized queries to do this.
They are far less prone to SQL injection attacks and don't have problems with special characters inside your query strings, too.
Regards,
mav
|
|
|
|
|
Hi,
I know vertical length,horizontal length and sweep angle. with these inputs i am calculating radius,height and chordlength. But i am not able to fix Rectangle co-ordinates (assuming x=100, y=250).
My calculation is this:
p1 = x- (r+length/2);
p2= y - (r + length/2
p3 = r * 2;
p4= r * 2;
But this is not working
Can any one help me.
Regards,
-- modified at 5:52 Monday 12th September, 2005
|
|
|
|
|
Standard question #1:
What do you mean by "not working"?
---
b { font-weight: normal; }
|
|
|
|
|
my rectangle co-ordinates are wrong. my arc is not coming properly. this is the code.
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Drawing.Drawing2D;
namespace FreeHand
{
///
/// Summary description for FillPolygon.
///
public class FillPolygon : System.Windows.Forms.Form
{
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.TextBox lengthBox;
private System.Windows.Forms.TextBox angleBox;
private System.Windows.Forms.Button button1;
public Graphics m_GraphicsToDrawOn;
protected Pen m_PenToDrawWith;
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.TextBox Vertical;
///
/// Required designer variable.
///
private System.ComponentModel.Container components = null;
public FillPolygon()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
InitializeGraphics(this);
//
// TODO: Add any constructor code after InitializeComponent call
//
}
///
/// Clean up any resources being used.
///
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
[STAThread]
static void Main()
{
Application.Run(new FillPolygon());
}
#region Windows Form Designer generated code
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///
private void InitializeComponent()
{
this.lengthBox = new System.Windows.Forms.TextBox();
this.angleBox = new System.Windows.Forms.TextBox();
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.button1 = new System.Windows.Forms.Button();
this.textBox1 = new System.Windows.Forms.TextBox();
this.label3 = new System.Windows.Forms.Label();
this.Vertical = new System.Windows.Forms.TextBox();
this.label4 = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// lengthBox
//
this.lengthBox.Location = new System.Drawing.Point(776, 104);
this.lengthBox.Name = "lengthBox";
this.lengthBox.TabIndex = 0;
this.lengthBox.Text = "30";
//
// angleBox
//
this.angleBox.Location = new System.Drawing.Point(776, 136);
this.angleBox.Name = "angleBox";
this.angleBox.TabIndex = 1;
this.angleBox.Text = "270";
//
// label1
//
this.label1.Location = new System.Drawing.Point(648, 104);
this.label1.Name = "label1";
this.label1.TabIndex = 2;
this.label1.Text = "Horizontal";
//
// label2
//
this.label2.Location = new System.Drawing.Point(648, 136);
this.label2.Name = "label2";
this.label2.TabIndex = 3;
this.label2.Text = "Angle";
//
// button1
//
this.button1.Location = new System.Drawing.Point(792, 192);
this.button1.Name = "button1";
this.button1.TabIndex = 4;
this.button1.Text = "button1";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(776, 64);
this.textBox1.Name = "textBox1";
this.textBox1.TabIndex = 5;
this.textBox1.Text = "0";
//
// label3
//
this.label3.Location = new System.Drawing.Point(648, 64);
this.label3.Name = "label3";
this.label3.TabIndex = 6;
this.label3.Text = "Rotate At";
//
// Vertical
//
this.Vertical.Location = new System.Drawing.Point(376, 72);
this.Vertical.Name = "Vertical";
this.Vertical.Size = new System.Drawing.Size(152, 20);
this.Vertical.TabIndex = 8;
this.Vertical.Text = "20";
//
// label4
//
this.label4.Location = new System.Drawing.Point(240, 72);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(72, 24);
this.label4.TabIndex = 9;
this.label4.Text = "Vertical";
this.label4.Click += new System.EventHandler(this.label4_Click);
//
// FillPolygon
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(936, 389);
this.Controls.Add(this.label4);
this.Controls.Add(this.Vertical);
this.Controls.Add(this.label3);
this.Controls.Add(this.textBox1);
this.Controls.Add(this.button1);
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
this.Controls.Add(this.angleBox);
this.Controls.Add(this.lengthBox);
this.Name = "FillPolygon";
this.Text = "FillPolygon";
this.Load += new System.EventHandler(this.FillPolygon_Load);
this.Paint += new System.Windows.Forms.PaintEventHandler(this.FillPolygon_Paint);
this.ResumeLayout(false);
}
#endregion
protected void InitializeGraphics(Form canvas)
{
IntPtr formHdc = canvas.Handle;
m_GraphicsToDrawOn =Graphics.FromHwnd(formHdc);
m_PenToDrawWith = new Pen(Color.Red);
}
int horilength=0 ;
int verticallength=0;
int length = 0;
float angleDeg ;
float angleRad;
int x=100;
int y=150;
int x1=300;
int y1=250;
int r=0;
int h=0;
private double ang = 45.0f;
private void button1_Click(object sender, System.EventArgs e)
{
horilength = int.Parse(lengthBox.Text);
verticallength = int.Parse(Vertical.Text);
length =(int) (Math.Sqrt(Math.Pow(horilength,2)+(Math.Pow(verticallength,2))));
//angleDeg = Math.Max(0.0f, Math.Min(90.0f, float.Parse(angleBox.Text)));
angleDeg = float.Parse(angleBox.Text)/2;
angleRad = angleDeg * (float)(Math.PI / 180);
ang= (float)Convert.ToDouble(textBox1.Text);
//ang = Math.Tanh((verticallength/horilength)*3.14/180);
//Graphics g = this.CreateGraphics();
//Pen pen = new Pen(Color.Red, 1);
// get circle radius
r = (int) (((double) length / 2) / Math.Sin(angleRad));
//
h = (int) (Math.Cos(angleRad) * r);
// draw arc
this.Invalidate();
}
protected override void OnPaint(PaintEventArgs e)
{
int p1=0;
int p2=0;
int p3=0;
int p4=0;
float st=0;
float sp=0;
this.textBox1.Text = Convert.ToString(ang);
Point rotatePoint;
if(r!= 0)
{
// p1 = x - (r + length /2);//(r + length/2);//+int.Parse(ang.ToString());
// p2= y - (r + length /2);//(r + length/2);
p1 = x - (r - length /2);
p2= y - ( r - h);
p3 = r * 2;
p4= r * 2;//(int)Math.Sqrt(Math.Pow(length,2)-Math.Pow( r,2)) ;
st= -45 + angleDeg;
sp= -2 * angleDeg;
//e.Graphics.DrawLine(m_PenToDrawWith, x, y, x-length, y-length);
e.Graphics.DrawLine(Pens.Blue,50,y,x,y);
e.Graphics.DrawLine(m_PenToDrawWith, x, y, x+horilength, y);
e.Graphics.DrawLine(m_PenToDrawWith, x+horilength, y, x+horilength, y+verticallength);
e.Graphics.DrawLine(m_PenToDrawWith, x, y, x+horilength, y+verticallength);
//e.Graphics.DrawLine(Pens.Green,50,250,100,250);
//e.Graphics.DrawLine(Pens.Green,50,250,100,325);
rotatePoint = new Point(x,y);
//e.Graphics.DrawRectangle(Pens.Black,p1,p2,p3,p4);
Matrix myMatrix = new Matrix();
myMatrix.RotateAt((float)ang, rotatePoint, MatrixOrder.Append);
// myMatrix.Rotate(ang, MatrixOrder.Append);
e.Graphics.Transform = myMatrix;
// e.Graphics.DrawRectangle(Pens.Black,p1,p2,p3,p4);
Rectangle rect= new Rectangle(p1,p2,p3,p4);
//e.Graphics.DrawRectangle(Pens.Red,rect);
//upper side
e.Graphics.DrawArc(Pens.BlueViolet ,rect ,st ,sp);
//
// if(angleDeg *2 <180)
// {
//
// angleDeg=180-(angleDeg *2 );
// rect= new Rectangle(p1,p2-Convert.ToInt32(angleDeg),p3,p4);
//
// }
//e.Graphics.DrawArc(Pens.Black ,rect ,st ,sp);
//Second Arc
//
// e.Graphics.DrawLine(Pens.Green,x1-50,y1,x1,y1);
// p1 = x1 - (r - length / 2);//+int.Parse(ang.ToString());
// p2= y1 - (r - h) ;
//
// if(angleDeg *2 < 180)
// {
// p2=p2-(180- Convert.ToInt32(angleDeg)*2);
// rect= new Rectangle(p1,p2,p3,p4);
// }
// e.Graphics.DrawRectangle(Pens.Red,rect);
// e.Graphics.DrawArc(Pens.Black ,rect ,-st ,-sp);
// Create pen.
//Pen blackPen= new Pen(Color.Black, 2);
// Create coordinates of rectangle to bound ellipse.
// float y1 = 0.0F;
//float width = r*2;
//float height = r*2;
// Create start and sweep angles on ellipse.
// Draw arc to screen.
//e.Graphics.DrawArc(blackPen, x1, y1, width, height, startAngle, sweepAngle);
}
//m_PenToDrawWith.Dispose();
//m_GraphicsToDrawOn.Dispose();
}
private void FillPolygon_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
{
}
private void FillPolygon_Load(object sender, System.EventArgs e)
{
}
private void label4_Click(object sender, System.EventArgs e)
{
}
}
}
|
|
|
|
|
Hello everybody,
I've got a form with multiple usercontrols which contain some textboxes. Is it
possible to adjust the tabindexes so it can hop from the textbox in the one control
to another and back. I tried something like this.
this.usercontrol1.textbox1.tabindex = 1
this.usercontrol2.textbox1.tabindex = 2
this.usercontrol1.textbox2.tabindex = 3
but this doesn't work. Can anyone tell me whether it is possible to do something like
this and how to achieve that.
With kind regards
Joris
|
|
|
|
|
This code works if u write it in the gotfocus event of the form. Does not work when written in the load event
|
|
|
|
|
I have a project by SampleApp with 4 usercontrol.cs files with it.
3 of them with same namespace Sample1.Other usercontrol by "SampleApp" with namespace Sample2.The 3 user controls are used in the SampleApp.I have built the project.
I have a TestApp of outputtype Windowsapplication where i wanted to place the SampleApp.dll by adding it in to the tool box.when i place the .dll on to the form,i am getting an exception as
Sample2.SampleApp error 'Specified cast is not valid'
Can anyone please let me know why i am getting this error.
Thanks & Regards
Lakshmieie
|
|
|
|
|