336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

Form.Location 이라는 속성을 이용해서 창의 위치를 결정할 수 있습니다.
그리고 Form.Show() 라는 메써드를 이용해서 창을 보여줄 수 있습니다.
그렇다면!!
위치를 지정하고 그 위치에 창을 띄울 수 있을 것 같은데... 어라? 잘 안됩니다 ㅡㅡ;
일단 Show() 메써드를 사용한 후에는 Location 속성을 이용해서 창이 잘 움직이는데 처음 시작할 때는 잘 안되는군요~
Show() 메써드를 실행하기 전에 지정한 Location 속성은 Form의 위치에 영향을 주지 못하는 것 같습니다.

이럴 때!!
Form.StartPosition 속성을 이용합니다.
오호라! 시작 위치를 지정할 수 있을 것 같은 속성 이름이군요!

Form.StartPosition 속성은 Point 객체가 아니고 FormStartPosition 이라는 열거형입니다.
그렇다면 어떻게 처음 위치를 지정할까요?

Form.StartPosition = FormStartPosition.Manual; //이렇게 지정해 주면 Location을 시작 위치로 사용합니다.
이 방법을 사용하면 Form을 원하는 위치에 띄울 수 있겠죠? ^^

form1.StartPosition = FormStartPosition.Manual;
form1.Location = new Point(10,10);
form1.Show();
블로그 이미지

By훈트

,
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

디렉토리를 생성할때 디렉토리가 생성되어 있는지 검사도 해야 한다.

Directory 나 DirectoryInfo 를 사용하면 디렉토리 생성 및 검사도 가능하다.

방법#1

if (Directory.Exists(rootPath) == false)

    Directory.CreateDirectory(rootPath);

방법#2

DirectoryInfo di = new DirectoryInfo(rootPath);

if (di.Exists == false)

{

    di.Create();

}



블로그 이미지

By훈트

,
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.
DateTime oldDate = new DateTime(2002,7,15);
DateTime newDate = DateTime.Now;

// Difference in days, hours, and minutes.
TimeSpan ts = newDate - oldDate;
// Difference in days.
int differenceInDays = ts.Days;

Console.WriteLine("Difference in days: {0} ", differenceInDays);
블로그 이미지

By훈트

,
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

C#에서 윈도우즈의 해상도를 가져오는 방법은 다음과 같다.

1. 

Screen.PrimaryScreen.Bounds.Width
Screen.PrimaryScreen.Bounds.Height

 

2.

System.Windows.Forms.SystemInformation.VirtualScreen.Width;

System.Windows.Forms.SystemInformation.VirtualScreen.Height;


이를 이용해 폼을 윈도우즈의 정중앙에 띄울수 도 있다.

 

this.Location = new Point(

   Screen.PrimaryScreen.Bounds.Width/2 - this.Size.Width/2,

   Screen.PrimaryScreen.Bounds.Height/2 - this.Size.Height/2

); 

 
1, 2 의 차이점은 듀얼모니터를 쓸경우 1은 모니터 1대의 해상도를 가져오고 2는 2대를 합한 총 해상도를 가져옵니다.


블로그 이미지

By훈트

,
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.
기본적인 좌표는
Control.MousePosition.X
Control.MousePosition.Y
이고 이놈을 그대론 절때 못 쓴다. LCD화면의 좌표를 보내주는거 같고

픽스 해야한다.

해당컨트롤놈.PointToClient(new Point(Control.MousePosition.X, Control.MousePosition.Y));

이렇게 하면 해당컨트롤을 기준으로 마우스 실제 상대좌표가 어딘가 뱉어낸다.

이값은 해당컨트롤.마우스이벤트(MouseArgsEvent e)의 e.X와 같다.

후후. 안그럼 패딩 뺴주고 지랄날리부르스해야한다. 

편리하군

PointToClient와 PointToScreen



블로그 이미지

By훈트

,
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.
1. 원본이미지와 퍼센트를 이용하여 크기조정하기.







2. 원본이미지와 Size를 이용하여 크기조정하기



블로그 이미지

By훈트

,
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

폼실행
Form1_Move
Form1_LocationChanged
Form1_StyleChanged
Form1_BindingContextChanged
Form1_Load
Form1_Layout
Form1_VisibleChanged
Form1_Activated
Form1_Shown
Form1_Paint
Form1_KeyUp

다른창으로 가림
Form1_Deactivate
Form1_Paint

다른창으로 가림 해제
Form1_Activated
Form1_Paint

클릭해서 다른창으로 가림 해제
Form1_Activated
Form1_Paint
Form1_MouseCaptureChanged

마우스 움직임
Form1_MouseEnter
Form1_MouseMove
Form1_MouseHover
Form1_MouseLeave

키보드 누름
Form1_PreviewKeyDown
Form1_KeyDown
Form1_KeyPress
Form1_KeyUp

창종료
Form1_FormClosing
Form1_FormClosed


[출처] 

블로그 이미지

By훈트

,
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.
Server=서버명;Database=DB명;User ID=접속아이디;Password=비밀번호;Trusted_Connection=False

예제)

String strConnection = "Server=222.222.222.222;Database=mydb;User ID=myid;Password=pw;Trusted_Connection=False";


블로그 이미지

By훈트

,
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

MemoryStream

Saving-Rebuilding InkCanvas Strokes

Load/Unload images into/from DB table

C# Image to Byte Array and Byte Array to Image Converter Class

 

Introduction

Recently I was looking for a class which could convert a System.Drawing.Image to byte[] array and vice versa. After a lot of searching on Google, I realised that it would be faster for me to write this class and also share it with the community.

The class which I wrote is called ImageConverter.cs. The class has two methods.

First method: Convert Image to byte[] array:

 Collapse Copy Code
public byte[] imageToByteArray(System.Drawing.Image imageIn)
{
 MemoryStream ms = new MemoryStream();
 imageIn.Save(ms,System.Drawing.Imaging.ImageFormat.Gif);
 return  ms.ToArray();
}

This method uses the System.Drawing.Image.Save method to save the image to a memorystream. The memorystream can then be used to return a byte array using the ToArray() method in the MemoryStream class.

Second method: Convert byte[] array to Image:

 Collapse Copy Code
public Image byteArrayToImage(byte[] byteArrayIn)
{
     MemoryStream ms = new MemoryStream(byteArrayIn);
     Image returnImage = Image.FromStream(ms);
     return returnImage;
}

This method uses the Image.FromStream method in the Image class to create a method from a memorystream which has been created using a byte array. The image thus created is returned in this method.

The way I happen to use this method was to transport an image to a web service, by converting it to a byte array and vice-versa.

Hope this class is useful to the community as well. The code of ImageConverter.cs can be downloaded from the link at the top of this article.

Rajan Tawate

Founder
Seegloo Web Meeting

 

 

 

 

 

 

 

--------------

 

Store Image into DB table

 Collapse Copy Code
...
byte[] content = ReadBitmap2ByteArray(fileName);
StoreBlob2DataBase(content);
...
protected static byte[] ReadBitmap2ByteArray(string fileName)
{
  using(Bitmap image = new Bitmap(fileName))
  {
    MemoryStream stream = new MemoryStream();
    image.Save(stream, System.Drawing.Imaging.ImageFormat.Bmp);
    return stream.ToArray();
  }
}

protected static void StoreBlob2DataBase(byte[] content)
{
   SqlConnection con = Connection;
   con.Open();
   try
   {
     // insert new entry into table
     SqlCommand insert = new SqlCommand(
     "insert into Images ([stream]) values (@image)",con);
     SqlParameter imageParameter = 
     insert.Parameters.Add("@image", SqlDbType.Binary);
     imageParameter.Value = content;
     imageParameter.Size  = content.Length;
     insert.ExecuteNonQuery();
   }
   finally
   {
      con.Close();
   }
}

Store Images for OLEDB provider

Some of us use OLEDB provider to communicate with SQL Server. In this case you should use the code below to store images into your DB. Pay attention to using '?' instead of '@image' in the SQL query.

 Collapse Copy Code
protected static void StoreBlob2DataBaseOleDb(byte[] content)
{
   try
   {
      using(OleDbConnection con = Connection)
      {
         con.Open();

         // insert new entry into table
         using(OleDbCommand insert = new OleDbCommand(
             "insert into Images ([stream]) values (?)",con))
         {
            OleDbParameter imageParameter = 
            insert.Parameters.Add("@image", OleDbType.Binary);
            imageParameter.Value = content;
            imageParameter.Size  = content.Length;
            insert.ExecuteNonQuery();
         }
      }
   }
   catch(Exception ex)
   {
      // some exception processing
   }
}

Get Image from DB table and show it

 Collapse Copy Code
 // get image
 DataRowView drv = (DataRowView) _cm.Current;
 byte[] content = (byte[])drv["stream"];
 MemoryStream stream = new MemoryStream(content);
 Bitmap image = new Bitmap(stream);
 
 ShowImageForm f = new ShowImageForm();
 f._viewer.Image = image;
 f.ShowDialog(this);

Conclusion

You can use this technique to work with any type of binary data without using storage procedures. Good Luck.

<FORM style="PADDING-BOTTOM: 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C10ZXh0Ij5Ib3cgdG8gdXNlIHRoZSBEeW5hbWljTWV0aG9kIGFuZCBJTEdlbmVyYXRvciBjbGFzc2VzIHRvIGNyZWF0ZSBkeW5hbWljIGNvZGUgYXQgcnVudGltZSB0aGF0IG91dHBlcmZvcm1zIHJlZmxlY3Rpb248L2Rpdj48L2xpPjwvdWw+ZAIJDw8WAh8AZ2RkAgsPZBYCZg9kFgICAQ9kFgJmD2QWAmYPFgQfBAUNUmF0ZUl0ZW1fOTMyMx8FZRYCAgYPZBYCAgEPD2QWAh8GBSJyZXR1cm4gcmF0ZUl0ZW0oOTMyMywyLHRydWUsdHJ1ZSk7ZAIbDw8WAh8AZ2RkAiEPFgIfAGhkAgsPDxYCHwIFJi9zY3JpcHQvQXJ0aWNsZXMvQXJ0aWNsZS5hc3B4P2FpZD05MzIzZGQCEQ8WAh8HBQsyNCBBdWcgMjAwNWQCEw8PFgQfBwUOU21pdGhhIFZpamF5YW4fAgUmL3NjcmlwdC9NZW1iZXJzaGlwL1ZpZXcuYXNweD9taWQ9Mjg5NzBkZAIVDxYCHwcFIkNvcHlyaWdodCAyMDA1IGJ5IE1heGltIEFsZWtzZXlraW5kZHoy3t5b1AFEWlnw6kJkhmg0NxIO" type="hidden" name="__VIEWSTATE">
<INPUT id="__EVENTVALIDATION" value="/wEWCALryJLaBgLAlMXDBwLBlMXDBwLClMXDBwLDlMXDBwLElMXDBwLP+++tCwK5upDkC+Baommd5pH6A8nKaeXZ0JWo3SoP" type="hidden" name="__EVENTVALIDATION">

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

 

</FORM> 

 

 

 

 

--------------------------

 

 

byte[] content = ReadBitmap2ByteArray(fileName);
StoreBlob2DataBase(content);
...
protected static byte[] ReadBitmap2ByteArray(string fileName)
{
  using(Bitmap image = new Bitmap(fileName))
  {
    MemoryStream stream = new MemoryStream();
    image.Save(stream, System.Drawing.Imaging.ImageFormat.Bmp);
    return stream.ToArray();
  }
}

protected static void StoreBlob2DataBase(byte[] content)
{
   SqlConnection con = Connection;
   con.Open();
   try
   {
     // insert new entry into table
     SqlCommand insert = new SqlCommand(
     "insert into Images ([stream]) values (@image)",con);
     SqlParameter imageParameter = 
     insert.Parameters.Add("@image", SqlDbType.Binary);
     imageParameter.Value = content;
     imageParameter.Size  = content.Length;
     insert.ExecuteNonQuery();
   }
   finally
   {
      con.Close();
   }
}

블로그 이미지

By훈트

,