For smart Primates & ROBOTS (oh and ALIENS ).

Showing posts with label c#. Show all posts
Showing posts with label c#. Show all posts

Saturday, February 06, 2016

update control value in C# Thread

How to update control value in C# Thread.



Use below sample of code:

Thread t1=new Thread();
String b="";
int all=0;
 private void button5_Click(object sender, EventArgs e)
 {
         
            t1 = new Thread(new ThreadStart(MyCodeRun));  t1.Start();
 }

void MyCodeRun()
{
           while (String.IsNullOrEmpty(b) || String.IsNullOrWhiteSpace(b))
            {
                this.BeginInvoke(new MethodInvoker(changeValue));
                all = all + 1;
                System.Threading.Thread.Sleep(1000);
            }
 }

 private void changeValue()
{
            label1.Text =all + "";
}
Share:

Tuesday, October 20, 2015

Video Watermark Remover

Problem:

Some time you have many videos that has watermark. you just hate that watermark and need to delete it. There are many watermark remover software but all are not free. so if you want a free video watermark remover then you are at present here right place.

Solution:


I have developed Video watermark remover software. it is 64 Bit Windows 7 desktop application, so you needed to .net framework 4.5 to run this application.




You can download it from here:

http://sourceforge.net/projects/unique-softwares/files/VideoWaterMarkRemover.part01.rar

http://sourceforge.net/projects/unique-softwares/files/VideoWaterMarkRemover.part02.rar

http://sourceforge.net/projects/unique-softwares/files/VideoWaterMarkRemover.part03.rar

http://sourceforge.net/projects/unique-softwares/files/VideoWaterMarkRemover.part04.rar

http://sourceforge.net/projects/unique-softwares/files/VideoWaterMarkRemover.part05.rar

http://sourceforge.net/projects/unique-softwares/files/VideoWaterMarkRemover.part06.rar

http://sourceforge.net/projects/unique-softwares/files/VideoWaterMarkRemover.part07.rar

http://sourceforge.net/projects/unique-softwares/files/VideoWaterMarkRemover.part08.rar

http://sourceforge.net/projects/unique-softwares/files/VideoWaterMarkRemover.part09.rar

http://sourceforge.net/projects/unique-softwares/files/VideoWaterMarkRemover.part10.rar

http://sourceforge.net/projects/unique-softwares/files/VideoWaterMarkRemover.part11.rar

http://sourceforge.net/projects/unique-softwares/files/VideoWaterMarkRemover.part12.rar

http://sourceforge.net/projects/unique-softwares/files/VideoWaterMarkRemover.part13.rar



Share:

Monday, October 19, 2015

Microsoft Office Interop Outlook

Problem:

Where to find library of Microsoft.Office.Interop.Outlook?

Solution:

To locate library of Microsoft.Office.Interop.Outlook you should look into below 2 folders:
C:\Program Files (x86)\Microsoft Visual Studio 12.0\Visual Studio Tools for Office\PIA\Office14
C:\Program Files (x86)\Microsoft Visual Studio 12.0\Visual Studio Tools for Office\PIA\Office15


Please note that folder could be "C:\Program Files\"

Share:

Wednesday, May 06, 2015

How to convert eps file to jpg file

Problem:

How to convert .eps file to .jpg file

Solution:

It is simple, use ImageMagick and below java code. if you expert in PHP or .Net then you can easily convert it same as me.

Example:

import="java.util.*"%>  
import="java.io.*"%>
 
try
    {
        Runtime runTime = Runtime.getRuntime();
        Process process = runTime.exec ("C:/Program Files/ImageMagick-6.5.4-Q16/convert.exe c:/Art1.eps c:/art1.jpg");
        //InputStream inputStream = process.getInputStream();
        //InputStreamReader   inputStreamReader = new InputStreamReader (inputStream);
        //BufferedReader bufferedReader = new BufferedReader(
inputStreamReader);
        ///String line = null;
        //while ( (line = bufferedReader.readLine()) != null )
        //    System.out.println(line);
        int exitVal = process.waitFor();
        System.out.println ("Process exitValue:  " + exitVal );
    }
    catch (Throwable t)
    {
        t.printStackTrace();
    }
Share:

Wednesday, April 22, 2015

File open Dialogbox show error System Threading ThreadStateException

Problem:

I am wondering when you get the error 'System.Threading.ThreadStateException' while using OpenFileDialog in C# Winform application. So how to solve this?

First we see the error details, after that I will show you solution.
See the screenshot below.
System.Threading.ThreadStateException



















Error is:
"An unhandled exception of type 'System.Threading.ThreadStateException' occurred in System.Windows.Forms.dll
Additional information: Current thread must be set to single thread apartment (STA) mode before OLE calls can be made. Ensure that your Main function has STAThreadAttribute marked on it. This exception is only raised if a debugger is attached to the process."

Code is:

System.Windows.Forms.OpenFileDialog openFileDialog = new OpenFileDialog();
openFileDialog.Title = "Select HTML/HTML5 file";
openFileDialog.InitialDirectory = "C:";
openFileDialog.Filter = "HTML files (*.html)|*.html|Flv files (*.htm)|*.htm";
openFileDialog.AutoUpgradeEnabled = true;
if (openFileDialog.ShowDialog() == DialogResult.OK)
{
String Chosen_File = openFileDialog.FileName;
       String inputExt = (Path.GetExtension(Chosen_File).ToLower());
       textBox1.Text = Chosen_File;
       textBox2.Text = Chosen_File + "_New" + inputExt;
}
It will show error on the line

if (openFileDialog.ShowDialog() == DialogResult.OK)


The full error code is:
=============================
System.Threading.ThreadStateException was unhandled
  HResult=-2146233056
  Message=Current thread must be set to single thread apartment (STA) mode before OLE calls can be made. Ensure that your Main function has STAThreadAttribute marked on it. This exception is only raised if a debugger is attached to the process.
  Source=System.Windows.Forms
  StackTrace:
       at System.Windows.Forms.FileDialog.RunDialog(IntPtr hWndOwner)
       at System.Windows.Forms.CommonDialog.ShowDialog(IWin32Window owner)
       at System.Windows.Forms.CommonDialog.ShowDialog()
       at CoreRenderer.Form1.button3_Click(Object sender, EventArgs e) in d:\CurrentProject\WinForm\VS2013Testing\CS\CoreRenderer\CoreRenderer\Form1.cs:line 121
       at System.Windows.Forms.Control.OnClick(EventArgs e)
       at System.Windows.Forms.Button.OnClick(EventArgs e)
       at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
       at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
       at System.Windows.Forms.Control.WndProc(Message& m)
       at System.Windows.Forms.ButtonBase.WndProc(Message& m)
       at System.Windows.Forms.Button.WndProc(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
       at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
       at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
       at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.Run(Form mainForm)
       at CoreRenderer.Program.Main() in d:\CurrentProject\WinForm\VS2013Testing\CS\CoreRenderer\CoreRenderer\Program.cs:line 21
       at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException:
=============================

Solution:

To overcome this problem you need to use Thread class. See below code that how to fix this error.

Example:

Create a method as below:
public void getfile() {
      System.Windows.Forms.OpenFileDialog openFileDialogAvi = new OpenFileDialog();
      openFileDialogAvi.Title = "Select HTML/HTML5 file";
      openFileDialogAvi.InitialDirectory = "C:";
      openFileDialogAvi.Filter = "HTML files (*.html)|*.html|Flv files (*.htm)|*.htm";
      openFileDialogAvi.AutoUpgradeEnabled = true;
      if (openFileDialogAvi.ShowDialog() == DialogResult.OK)
      {
         String Chosen_File = openFileDialogAvi.FileName;
         String inputExt = (Path.GetExtension(Chosen_File).ToLower());
         Invoke((MethodInvoker)delegate
         {
               textBox1.Text = Chosen_File;
               textBox2.Text = Chosen_File + "_New" + inputExt;
         });
      }
   }


On click button access the above method:

private void button2_Click(object sender, EventArgs e) {
       Thread threadGetFile = new Thread(new ThreadStart(getfile));
       threadGetFile.ApartmentState = ApartmentState.STA;
       threadGetFile.Start();         
}

Share:

Wednesday, March 25, 2015

Email Blaster

Email Blaster
*Features
- Send unlimited emails.
- Send test email, so you can see your email format and looks.
- Show real time progress in counting sent emails.
- Show progress in percentage(%)
- Send email both format Text and HTML format.
- Alternate Solution of Cron Job(Less feature).
- Alternate Solution of SQL Agent Job(Less feature).
- Solution of Script Timeout.






















































Share:

Thursday, March 12, 2015

Cell align top in dataGridView in c#

Use one line code as below:

dataGridView1.Columns["Question"].DefaultCellStyle.Alignment=DataGridViewContentAlignment.TopLeft;
Share:

Get Volume Serial Number of Drive in C#

Listed below the code use in your project to get Volume serial number

//let's show C drive's volume serial number
String d = "c";
try {
    System.Management.ManagementObject dsk1 = new System.Management.ManagementObject(@"win32_logicaldisk.deviceid=""" + d + @":""");
    dsk1.Get();
    string s1 = dsk1["VolumeSerialNumber"].ToString();
    MessageBox.Show(s1);
}
catch (Exception ee)
{
    MessageBox.Show(ee.ToString());

}
Share:

SEND EMAIL FROM WINFORM

Some times you want to open microsoft outlook from microsoft winform and then type the mail message and send it. use below one line of code.


System.Diagnostics.Process.Start("mailto:XYZ@XYZ.COM");
Share:

HOW TO MAKE TRANSPARENT PNG FILE IN C# VB.NET .NET

Problem:

I was working a project where watermark in pdf file as text. but after some time requirement has been changed. the requirement is put watermark as png file in pdf instead of text. The first task was generate transparent png file in C# with given text. the text should be show diagonal. listed below the few lines of code.
HOW TO MAKE TRANSPARENT PNG FILE IN C#





















Solution:

See the below code:

Example:

string text = " this is diognal text for watermark in transparent png file";
Bitmap bmp = new Bitmap(400, 800);
int x = 200, y = 400, angle=55;
Graphics g = Graphics.FromImage(bmp);
System.Drawing.Font f = new System.Drawing.Font("Arial", 25, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Pixel);
g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit;
g.Clear(Color.Transparent);
g.TranslateTransform(x, y);
g.RotateTransform(-angle);
g.TranslateTransform(-x, -y);
SizeF size = g.MeasureString(text, f);
g.DrawString(text, f, Brushes.Black, new PointF(x - size.Width / 2.0f, y - size.Height / 2.0f));
bmp.Save("test.png", System.Drawing.Imaging.ImageFormat.Png);
g.Dispose();
 
Share:

GET MAC ADDRESS IN C# VB.NET

Problem:

Some time you want to develop a software in C# or Vb.net that will run only on specific computer system. for this you use mac address of that system.

Solution:

Here the C# code that will fetch mac address.

Example:

System.Net.NetworkInformation.NetworkInterface[] nic= System.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces();
String macAddress = string.Empty;
foreach (System.Net.NetworkInformation.NetworkInterface ni in nic)
{
   System.Net.NetworkInformation.IPInterfaceProperties properties=ni.GetIPProperties();
   macAddress = ni.GetPhysicalAddress().ToString();
   if (macAddress != String.Empty) {
                        MessageBox.Show(macAddress);
                        return;
   } 

}



Share:

SHOW FORM WITH IN FORM AS IMAGE


Problem:

Some time you have already created many form. then are opening separately when you click on any button in MDI Form or separate in C# winform.  After soe time requirement has changed. the new requirement is to open new form in the same form from where you are clicking button.
For better understand see below image

Show Form with in form as image

















Solution:


Use panel control to show form 


Example:

panel1.Visible = true;
panel1.Controls.Clear();
StandardTest f1 = new StandardTest(); // this the form which you want to show
f1.TopLevel = false;
panel1.Controls.Add(f1);
panel1.Width = 1100;
panel1.Height = 620;
f1.Width = 1100;
f1.Height = panel1.Height - 0;
f1.Dock = DockStyle.Left;
f1.Show();



Share:

Thursday, January 08, 2015

Paragraph overlapping problem in itextsharp

Problem:

If you are working with itextSharp in Dot net winform C# or VB.net then you are very familiar with Paragraph. if  Paragraph font size is big then the Paragraph text will overlap as below example image.

Paragraph overlapping problem in itextsharp
Paragraph overlapping problem in itextsharp


So  how to overcome this problem?

Solution: 

To overcome paragraph text overlapping problem in itextsharp you will use  Paragraph SpacingAfter property.

Example:

Use below C# code, you can convert it into VB.net code if you are working in VB.net.

Paragraph para= new Paragraph("This is a test");
para.Alignment = Element.ALIGN_CENTER;
para.SpacingAfter=50f;
doc.Add(para);
Share:

Sunday, January 04, 2015

itextSharp.text.pdf.badpasswordException PdfReader not opened with owner password

Problem:

If you are using iTestShap in Dot net application and generating PDF with owner passward. After that you are trying to open that password protected in again in Dot net code then you may face the error or exception of itextSharp.text.pdf.badpasswordException PdfReader not opened with owner password.

Solution:

This is because you are not supplying the password while you opening that pdf file in itextsharp using PdfReader.

Example:

Creating Pdf file using owner password:

PdfWriter docWriter = PdfWriter.GetInstance(doc, new FileStream(pdfFileName, FileMode.Create));
byte[] OWNER = System.Text.Encoding.UTF8.GetBytes("mypassword");
docWriter.SetEncryption(null, OWNER, PdfWriter.ALLOW_PRINTING, PdfWriter.STANDARD_ENCRYPTION_128);

Now you are trying to open that file:

PdfReader pdfReader = new PdfReader(pdfFileName);

Correct code:

byte[] OWNER = System.Text.Encoding.UTF8.GetBytes("mypassword");
PdfReader pdfReader = new PdfReader(pdfFileName, OWNER);

So conclusion is that be sure you are supplying the password while opening the password protected file in PdfReader in C# or VB.net code:
Share:

Tuesday, December 30, 2014

System properties dialog box


Problem:

Sometime you are developing a software in the winform environment and yo need to to
open different system properties dialog box from your software. then How to open windows System Properties Dialog box?

System properties dialog box
















Solution:

To open system properties dialog box you will run "shell32.dll" from "rundll32.exe".

Example:

To open System Properties dialog box:
ans = Shell("rundll32.exe shell32.dll,Control_RunDLL sysdm.cpl @1", 6)
To open Sound and Audio Devices Properties:
ans =Shell("rundll32.exe shell32.dll,Control_RunDLL mmsys.cpl @1", 6)
To open Date and Time Properties:
ans = Shell("rundll32.exe shell32.dll,Control_RunDLL timedate.cpl", 6)
To open Internet Properties:
ans =Shell("rundll32.exe shell32.dll,Control_RunDLL inetcpl.cpl,,0", 6)
To open Keyboard Properties:
ans = Shell("rundll32.exe shell32.dll,Control_RunDLL main.cpl @1", 6)
To open Mouse Properties:
ans = Shell("rundll32.exe shell32.dll,Control_RunDLL main.cpl @0", 6)
To open Regional and Language Options:
ans = Shell("rundll32.exe shell32.dll,Control_RunDLL intl.cpl,,0", 6)
To open Add or Remove Programs:
ans = Shell("rundll32.exe shell32.dll,Control_RunDLL appwiz.cpl,,1", 6)
To open Display Properties:
ans =Shell("rundll32.exe shell32.dll,Control_RunDLL desk.cpl,,0", 6)
To open Game Controllers:
ans =Shell("rundll32.exe shell32.dll,Control_RunDLL joy.cpl", 6)
To open Phone and Modem Options:
ans =Shell("rundll32.exe shell32.dll,Control_RunDLL modem.cpl", 6)
Share:

Ads Inside Post

Powered by Blogger.

Archive