How to load an image into a PictureBox - PictureBox Example Part 1






In this mini tutorial I'll explain you how you can set the image to the PictureBox object using the Visual Studio IDE. There are several ways of doing this. The one mentioned here will load an image from a file using the filechooser.
I will explain other ways of loading images at runtime and from a resource object in future posts.


  1. Create a Windows Form Application Project.
  2. Drag a PictureBox Object to the window in the visual designer.
  3. Set the PictureBox image property to the image file you want (select local resource and click "Import").
  4. Done, Run your application.
 note: There is no code to add as this method only uses the Visual designer to accomplish this.

Screenshots below:

Create a Windows Form Application Project
Drag a PictureBox Object to the window in the visual designer.
Set the PictureBox image property to the image file you want.
Set the PictureBox image property to the image file you want (select local resource and click "Import").
Choose the file you want to load.
You can add more files to your resource if you want. Click Ok

The Image is displayed on the picturebox.
Run the Application (F5).

ComboBox Part 1 - adding items to the combobox




The ComboBox object provides the same benefits as a list does but it has the ability to expand and contract saving a lot of space in your windows form application.


In the next Quick Example, I'll show you how to add a ComboBox to a Windows Form Application and how to add items in it in two different ways.


1- By passing a range of items (in a list)
2- Adding a specific item by clicking a Button.



  1. First, create a Windows Form Application Project

    2. Drag a ComboBox Object to your Window.


    3. Add some code:

     
     I created a List items to store some strings that will then be added at the Load event.
  List<string> items = new List<string>() { "1-Lucia", "2-Mauricio","3-Frank","4-Dog" };

   4. At the Load Event type this line.

    comboBox1.Items.AddRange(items.ToArray());

 5.Then I added a button to show another way of adding items to the combobox
 In the Button Event put this line:

 comboBox1.Items.Add(comboBox1.Items.Count+1+"-Item Added by Button");

FINISHED.


The full Code below (it is all commented)

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace ComboBoxTest
{
    public partial class Form1 : Form
    {
        //creates and initialize a list with strings
        //(could contain any type of object)
        List<string> items = new List<string>() { "1-Lucia", "2-Mauricio", "3-Frank", "4-Dog" };
       
        public Form1()
        {
            InitializeComponent();
        }//constructor

        //The action takes part in the Load event, it could be a button or any other event.
        private void Form1_Load(object sender, EventArgs e)
        {
            //here we load the combobox with the list
            comboBox1.Items.AddRange(items.ToArray());
            //we set the selected to "1-Lucia", it also work with any kind of objects.(it depends on
            //what you put in the list.
            comboBox1.SelectedItem = "1-Lucia";
        }

        private void button_add_Click(object sender, EventArgs e)
        {
            //here we add an item to the combobox manually
            //"comboBox1.Items.Count+1" is just to show the apropiate index in the list
            //it calculates how many items are in the combobox and increments the value by 1
            comboBox1.Items.Add(comboBox1.Items.Count+1+"-Item Added by Button");
        }

      
    }
}



Screenshots:



At this point the ComboBox contains the List.


 

After the add button was clicked. The combobox contains now a new item.



Part 2 will cover the remove method and other combobox specific properties.


See you in the next C# Quick Example.
   

HOW TO LOAD ANY FONT FROM A FILE DIRECTLY



Hi, In a previous post, I explained you how to embed a ttf file into the .exe file and loading it to the window form using Visual C# or Microsoft Visual Studio.

Now I am going to explain you how you can load the font file directly at runtime, without the need of adding the .ttf  or any other type of file to the resources.

Let's take a quick look at what are we going to do:

1- Create a Windows Form Application
2 - Add the System.IO namespace and the System.Drawing.Text namespac

  • using System.IO;
  • using System.Drawing.Text;

3 - Add a Label to the window form for displaying purposes.

Now, I will load the file in the Load Event just to be quick with this. So add the Load event to the form.
If you don't know how to do this, just double click the Window Bar of your window preview.

I am going to create a Method called LoadFontFamily that returns a FontFamily and is private.

code:


private FontFamily LoadFontFamily(string fileName, out PrivateFontCollection _myFonts)
        {
            //IN MEMORY _myFonts point to the myFonts created in the load event 11 lines up.
            _myFonts = new PrivateFontCollection();//here is where we assing memory space to myFonts
            _myFonts.AddFontFile(fileName);//we add the full path of the ttf file
            return _myFonts.Families[0];//returns the family object as usual.
        }
//NOW THE LOAD EVENT WHERE WE ARE GOING TO MAKE THE CALL TO THIS METHOD AND MODIFY THE LABEL.FONT PROPERTY TO USE OWR FONT



private void Form1_Load_1(object sender, EventArgs e)
        {
            PrivateFontCollection myFonts; //CREATE A FONT COLLECTION

            //CREATES A FONTFAMILY
            //(LOOK THE out word in the parameter sent to the method, that will modify myFonts object)
            FontFamily family = LoadFontFamily(@"C:\Downloads\Backlog Normal.ttf", out myFonts);

            //CREATES A FONT FOR LATER USE
            Font theFont = new Font(family, 20.0f);

            //HERE WE SET THE LABEL FONT PROPERTY TO THE ONE WE JUST LOADED
            label1.Font = theFont;
            label1.Text = "HELLO WORLD!";
        }


screenshots:





Have a nice day.

cnet cwp-854 driver windows 7

Updated Download Link 05/09/2015 !!!

If you have this wonderful pci wireless card and you switched to any Windows 64 bits edition (XP/VISTA/7/8), you probably have to install this card driver again. 

Actually it was no easy job for me to find it in the web back when it happened to me.
As it cost me some time to find it, I'll save you that time.
This driver also works for the 32 bits editions.












 





The 64 driver version was not hosted in Cnet.com site. So I emailed the chipset manufacturer Ralink and after a week they replied with this link. They told me that the driver I needed was the one for the "RT2561ST" chipset.




RALINKTECH.COM Download Driver CWP-854 32/64 bits Windows (2000/xp/vista/7/8)


 Download Driver updated 14/04/2015

IMPORTANT !!! 

password so you can uncompress it : hongouru.blogspot.com



  

ArrayList in C#.




In this post, I'll show you How to use the C# ArrayList Object Class. I tried to use as many Properties and Methods the ArrayList Class has to offer as possible.


The ArrayList Object resides in the System.Collections namespace, that is why you must include that namespace in the class that will use it. You achieve this by adding:

using System.Collections;
 



using System;
using System.Linq;
using System.Text;
using System.Collections;
namespace ArratsTest
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("********* BEGIN OF APROACH 1 ******)\n");

            ArrayList aList = new ArrayList();
            //ADD ELEMENTS MANUALLY
            aList.Add("ONE");
            aList.Add("TWO");
            aList.Add("THREE");
            aList.Add("FOUR");
            aList.Add("FIVE");
            aList.Add("SIX");
            aList.Add("SEVEN");

            //ROMOVE BY OBJECT MATCH
            aList.Remove("THREE");
            //ROMOVE BY OBJECT INDEX (ZERO BASED INDEX)
            aList.RemoveAt(0);
            //REPLACE "SIX" WITH "6"
            aList[3] = "6";

            //ITERATES OVER THE LISTLIST
            foreach(string str in aList)
            {
                //PRINTS OUT EACH ELEMENT
                Console.WriteLine(str);
            }

            Console.WriteLine("\n********* END OF APROACH 1 *********)\n\n" +
                              "********* BEGIN OF APROACH 2 *******");
                              
            //ANOTHER APROACH
            //CLEAR THE LIST (GARBAGE COLLECTOR IS CALLED
            aList.Clear();

            //INITIALIZE aList WITH 4 VALUES.
            aList = new ArrayList(){"Mauricio","Lucia","Peter","Jhon"};

            //ORDER ALPHABETICALLY (if no IComarer was defined)
            aList.Sort();

            //PRINTS THE QUANTITY OF ITEMS STORED IN THE LIST
            Console.WriteLine("\nNUMBER OF ITEMS: "+aList.Count+"\n");

            //ITERATES OVER THE ARRAYLIST
            foreach (string str in aList)
            {
                //PRINTS OUT EACH ELEMENT
                Console.WriteLine(str);
            }
            Console.WriteLine("\n********* END OF APROACH 2 *********");

            //END MESSAGE
            Console.WriteLine("\n\nPRESS ANY KEY TO QUIT");
            Console.ReadKey();
        }
    }
}



C# HOW TO USE THE LIST OBJECT




In this short example I will show you how easy it is to actually create a List object and add some objects to it.

The List Object resides in the System.Collections.Generic;

That's why you must include that namespace before creating the List Object.

That it achieved by adding this line at the top of your .cs file.
using System.Collections.Generic;

with that said, let's jump to the code.


****************************************************

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.Generic;

namespace List_Test
{
    class Program
    {
        static void Main(string[] args)
        {
               // Creates the List Object and assign space to it.
            List<string> list = new List<string>();

            list.Add("one");//adds "one" to the list
            list.Add("two");//adds "two" to the list
            list.Add("three");//adds "three" to the list
           

            /*ITERATES OVER THE LIST OF TYPE STRING, IN EACH ITERATION
                  THE ACTUAL VALUE IS ASSIGNED TO THE TEMP VARIABLE tempString*/
            foreach (string tempString in list)
            {
                    //shows the ToString() method return string in the Command Prompt.
                Console.WriteLine(tempString.ToString());
            }

            //END MESSAGE
            Console.WriteLine("END, press any key to quit.");
            Console.ReadKey();//WAITS FOR USER INPUT TO CLOSE THE APPLICATION
        }
    }
}
********************************************************
SCREENSHOTS:

Step 1 :
Add the System.Collections.Generic to the top.


Step 2:
Place The code in the Main method.
 Step 3:
Run the application. (F5 if using Visual C# or Microsoft Visual Studio)

I hope it helped you out in some way.


C# HOW TO - HELLO WORLD application




This program, only prints out "Hello World!" to the default output. For C# with a Windows machine, this is the Command Promt.
To get Started:


**********************************************************************

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1 // THE NAMESPACE, NOT THAT IMPORTANT AT THIS TIME LIVE IT AS IS
{
    class Program // CLASS NAME THIS NAME REPRESENTS THE "Program" Object
    {
        static void Main(string[] args) //THIS IS WHERE THE EXECUTION BEGINS
        {
            Console.WriteLine("Hello World!"); //PRINTS THE LINE IN THE CONSOLE
            Console.ReadKey(); //BLOCKS UNTIL YOU PRESS A KEY (FOR DISPLAY PURPOSES)
        }
    }
}

**********************************************************************
  • Open Visual C# Express or Microsoft Visual Studio 2008 or 2010 or whatever version you like.
  • Go to File > New Project > Console Application. (check the bottom for screenshots on how to do this)
  • The Only two lines I added were:
  1. Console.WriteLine("Hello World!"); 
  2. Console.ReadKey(); 
  • The green text is used for giving additional info on why you put a specific line of code, they are called comments. You can write whatever your want after the // as it will be considered as short comments.
    For a multiline comment you can use or //
                                                               //
    or group your comment like this /* your comment here */

Now Press the Start Debugging button to compile and run the application.



File > New Project.


  

Now choose Console Application.



Final Code, generated by Visual C# Express plus the two lines I added.


Program running.

 
Any comments or special requests on how to do anything with in the C# language, I'll be glad to help you if it's in my scope. Thanks and have a nice day.

FLASH 10.1.85.3 DUAL MONITOR FIX




This workaround fixes the issue that prevents to  watch a video in your second screen while using your pc. For those who didn't try it yet, if you watch a video in fullscreen mode, you won't be able to use the other screen, because at the moment you make a click in the other screen, the video resizes back (FLASH FAIL!).
With that said, let's jump to the solution.

Step 1:

Make sure you know which Flash Player version is currently installed on your pc.
The best way to do this, is by opening a web browser to
www.youtube.com and play a any video you like.Then right click on the video while playing and  choose "about.." You'll be taken to the flash player about page, where it says your current version.

IT HAS TO SAY 10.1.85.3 to continue with this tutorial.

Step 2:

I'll resume the next steps.
You will have to modify a .dll file with an hex editor, remember to save a backup.
Don't worry, it is really a peace of cake.
Download the hex editor XVI32.


Step 3:

Now Open this file with XVI32
If you have Windows 32 Bits (XP/VISTA/7) installed:
C:\Windows\System32\Macromed\Flash\NPSWF32.dll

If you are on Windows 64 Bits (XP/VISTA/7) installed:
C:\Windows\SysWOW64\Macromed\Flash\NPSWF32.dll

MAKE A BACK UP OF THE FILE BEFORE ANYTHING ELSE!
note: if you want this solution to be applied for Google Chrome
then the file is located in:
C:\Users\YOURUSER\AppData\Local\Google\Chrome\Application\6.0.408.1\gcswf32.dll

 (make sure you change your username in the "YOURUSER" area.

Step 4:    

IN XVI32 go to Adress > Go to.
Then paste this in the search query 180DA7.
Look the line  that contains 48 74 39 83 E8 07
Then REPLACE 74 39 with 90 90 without the quotes of course.
We almost finish.!
Now save the changes. (it won't let you modify the file if any application   is using it, just close the youtube video.
Make sure that the  NPSWF32.dll backup file is in another directory.
If you just copy and paste the NPSWF32.dll file it won't work.
I believe that an integrity check is done inside the directory every time you
play a flash video and it will detect the file copied.
Dont leave it in the same directory as the modified NPSWF32.dll because it wont work.
Well try it if you don't believe me. I don't know why, but it is just true, I double checked it.

C# How to Add Fonts ttf True Type Fonts to your Window Form application in Visual Studio. (UPDATED)




This is a guide on how to add, use and work with a ttf font when you don't have it installed on your system.

With this howto you'll be able to:


  • c# add font
  • new font add in C#
  • install fonts with c sharp
  • c# font ttf
  • adding ttf file in vs 2010
  • how to dynamically install a .ttf file using c#
  • install font c# ttf
  • C# add Font to Project
  • ttf c#
  • c#" visual studio adding fonts
  • c# add font to a solution
  • add font c#
  • True type fonts in C#
  • c# 2010 add ttf
  • how to install font visual studio



Begins here...


When you create a C# solution "Window Form", or project in  Visual C# Express, Microsoft Visual Studio 2005/2008/2010,  you can select the fonts easily  just by selecting them from the properties.

But the problem exists when you want to use a specific TTF True type font, that could or could not be installed in the system.

Then, you need to include them into the resources of your project, so it can be obtained as a bytes array that will be loaded through a stream to a PrivateFontCollection object.



Here are the 6 steps I did to perform this.

Step 1:
Add the .ttf file to Resources (right click on your solution and select properties see the screenshot below)

Step 2:

A tab will be displayed with options and properties for our project.
Go to Resources > Add Existing File :



Look for the .ttf file in your Hard Drive:





Step 3:

Then we change the properties of the added resource (the .ttf file).
Select the FileType option and change it to "Binary".





Step 4:

Go back to your Solution Explorer view.
You will now see the Resources Directory created.
Choose your font file under this directory and select "Properties".






Change the Build Action option to: "Embedded Resource" (so the bytes array will be inside the .exe file)
(in this way there's no need to install the font in another machine).




Step 5: (Code)



Add this:









Text Version:

using System.Runtime.InteropServices;
using System.Drawing.Text;




Inside the class make a call to gdi32.dll.





Text Version
[DllImport("gdi32.dll")]
private static extern IntPtr AddFontMemResourceEx(IntPtr pbFont, uint cbFont, IntPtr pdv, [In] ref uint pcFonts);



Note that I've created two objects, one FontFamily object called "ff" and another Font object called "font".

FontFamily ff;
Font font;

Now two methods:
One Loads the PrivateFontCollection object and the other  just applies the font to the label.

The first one


**CargoPrivateFontCollections means (LoadPrivateFontCollection)**



Text Version

private void CargoPrivateFontCollection()
{
// Create the byte array and get its length

byte[] fontArray = FuentesTTF.Properties.Resources.Baby_Universe;
int dataLength = FuentesTTF.Properties.Resources.Baby_Universe.Length;


// ASSIGN MEMORY AND COPY  BYTE[] ON THAT MEMORY ADDRESS
IntPtr ptrData = Marshal.AllocCoTaskMem(dataLength);
Marshal.Copy(fontArray, 0, ptrData, dataLength);


uint cFonts = 0;
AddFontMemResourceEx(ptrData, (uint)fontArray.Length, IntPtr.Zero, ref cFonts);

PrivateFontCollection pfc = new PrivateFontCollection();
//PASS THE FONT TO THE  PRIVATEFONTCOLLECTION OBJECT
pfc.AddMemoryFont(ptrData, dataLength);

//FREE THE  "UNSAFE" MEMORY
Marshal.FreeCoTaskMem(ptrData);

ff = pfc.Families[0];
font = new Font(ff, 15f, FontStyle.Bold);
}


THE SECOND METHOD JUST LOADS THE LABEL CALLED  "label1"
(the "W" is over this.label1.Font = new Font(ff, 20, fontStyle);  (SORRY)






Text Version

private void CargoEtiqueta(Font font)
{
      float size = 11f;
      FontStyle fontStyle = FontStyle.Regular;

      this.label1.Font = new Font(ff, 20, fontStyle);

}



Step 6:

Call the two methods "CargoPrivateFontCollection()" and "CargoEtiqueta(Font font)",
I made the call from the Load event in the windows form but do it where you please, so the font is displayed correctly from the beggining. (it could be called from a button or thousands of places more)




Text Version

private void Form1_Load(object sender, EventArgs e)
{
       CargoPrivateFontCollection();
       CargoEtiqueta(font);
}



FINAL STEP: DONE!

IT's READY





"ESTA ES LA FIEMTE!" means "THIS IS THE FONT!"

NOTE: IMPORTANT!!!!!!

WHEN CREATING THE FONT IN THE "CargoPrivateFontCollection()" method
make sure you choose a FontStyle that's suitable for your font, otherwise it won't work and it will just display a normal default font.
Make sure you know what FontStyles your .ttf can handle



Hope it helps.

LOTS OF .TTF FREE HERE www.creamundo.com



YOU SHOULD ALSO READ C# HOW TO LOAD A FONT FROM A FILE DIRECTLY

NEED LEGAL FONTS ??
GET THIS ONES




2 ads