Tuesday, November 30, 2010

Common C# Controls

    There are a TON of controls in the C# toolbox, which is by default docked on the left side of your C# windows.  If you need a certain something on your form, there's probably a control for it in the toolbox.  The problem is: What is that control I need?

    Here's a quick list of the controls I feel are the most useful, the 3-letter prefix I use, and what they are for.

    Before we start, however, I would like to say that the following properties are pretty much always important:
    • Name is how your control will be referenced in your code.
    • Anchor is how your control will change in size/position when your form is resized.
    • Enabled is whether your control is usable.
    • Location is where the control is.
    • Size is how large your control is.
    • Text is what is displayed through your control.
    • Visible is whether or not your control can be seen.
    • TabIndex arranges the order of the controls that are selected as the user repeated presses the Tab key.
    And remember, the Click event is important for nearly every control because it's what happens when the control is clicked.

    Now, here's the list:
    • Form: (frm) This is what holds everything together!
      • Properties:
        • FormBorderStyle is your type of form.  I like to choose FixedDialog to make sure the user can't resize the form.
        • Icon is the picture displayed in the left of the title bar.
        • TopMost is whether your form will stay on top of all other windows (except other TopMost forms) like Task Manager.
        • MaximizeBox and MinimizeBox are whether the Form can be maximized or minimized, respectively.
        • ShowInTaskbar is whether your form will be shown in the Windows taskbar.
      • Events:
        • FormClosing is when your form is closing and you can stop it from closing by putting "e.Cancel = true;" in the method.
    • Button: (btn) The heart and soul of a form.  There's almost nothing useful you can make without a button.
    • Label:  (lbl) This is just some text that describes something on your form.  Not much more to it.
    • TextBox: (txt) A box for the user to put some text in.
    • CheckBox: (chk) This is a toggle between checked and unchecked.  In your code to test whether or not the box is checked, use: "chkCheckBoxName.Checked"
    • RadioButton: (rad) Similar to a CheckBox, except only one can be checked at a time in a group.  The same thing as the CheckBox to check whether or not the RadioButton is checked.
    • GroupBox: (grp) Used to group similar controls or have multiple groups of RadioButtons, since checked RadioButtons in a GroupBox don't affect other RadioButtons not in the GroupBox.
    • ComboBox: (cmb) A drop-down list for the user to select from.
    • Timer: (tmr) Activates an event every time the timer "ticks" based on a set interval.
    • NumericUpDown: (nud) Lets the user choose the number.  Use the Value property to get/set the number shown.
    • ProgressBar: (prg) Shows progress in a bar, like in an installer.  Use the Value property to get/set how full the bar is, and use Maximum and Minimum to set the bounds for the numbers in the ProgressBar.
    • TrackBar: (trb) Shows a sliding value bar that lets the user set something by sliding a downward pointed arrow.  You've probably seen this in Windows, such as when you change your mouse sensitivity.
    • BackgroundWorker: (bgw) Runs stuff in the background.  It's very useful because running long segments of code or long loops causes the form to freeze up, so running the same task with the BackgroundWorker allows the form to still be responsive while taking on another task.  It's multithreading!
    I hope some of this sparked some new ideas for you!  Maybe you should implement some of these into your new programs.  Or update some of your older ones with more appropriate controls.

    Monday, November 29, 2010

    How to Build a Computer

    Before you ignore this post because you don't think you can, I'm going to tell you that anybody can do it who has the funds and the desire to do so.

    Believe it or not, finding the right parts is actually harder than assembling the computer.  Nowadays, it's nearly impossible to put parts in backwards.  But I'm getting ahead of myself.  Let's find out what parts actually go in a computer.
    • Motherboard (~$80-$100).  This component basically everything else you have.  Make sure there are enough slots for everything.  Usually, there is sound output and a spot for your Ethernet (Internet connection) cable.  Sometimes you also get on-board integrated video output, but that's not very powerful and probably can't support multiple monitors.
    • CPU (Central Processing Unit) (~$200).  The heart of your computer.  This is also called the processor and pretty much does all the calculating and makes your computer run.  How fast your computer is has a lot to do with how fast your CPU is.  Everyone should get a decent CPU because it is important to everyday users and gamers alike.
    • RAM (Random Access Memory) (~$75).  This is the temporary storage space for your computer.  Having lots of applications opoen will mean that you'll need a lot of memory to hold them.  Your CPU writes its stuff down on the RAM, so the more RAM you have, the bigger/more applications you can open.
    • PSU (Power Supply Unit) (~$75).  This supplies power to your components.  You need to make sure that you have enough power to drive all your compoents, so see this PSU wattage calculator to get a rough estimate.  You'd also want to make sure that there are enough wires coming from your PSU to supply power to everything that needs it.
    • Hard drive (~$75).  This stores all your information.  Everything that you save goes on the hard drive.  You'll want to make sure that it's big enough to store everything you want.  Games and movies are especially big and can take up a lot of space.
    • Optical/CD/DVD drive (~25).  You'll probably want one of these just so you can read/write CDs and DVDs.  A relatively cheap one is usually fine for most people.  Some like to have 2 for flexibility.
    • Video/graphics card (~$200).  I'll probably get attacked for saying this, but a video card is actually optional.  If you're just going to be a light user, integrated graphics on your motherboard might do the trick, or if you don't have that, just getting a really cheap one might be fine.  Gamers, however, will need a graphics card, and probably a powerful one, depending on what kind of games you want to play.
    • Sound card.  This is supposed to make the sound quality better or something, but I think onboard sound on the motherboard is perfectly fine.
    • Wireless card.  If you're going to be far away from your router (or your neighbor's router -- just kidding), then you'll probably want to go wireless.  Otherwise, wired Internet is fine and in fact better.
    • Case (~$40).  Where all your stuff goes.  You probably don't need a bunch of fancy lights and features, so just make sure you have some (~2-3) fans if you're somewhat of a powerful user, but in most cases 1 or even no fans will still work.
    You can build a computer ranging from $300 to $3,000.  The "proposed" spending value totals to around $800 for a decent gaming computer.  Then you need to pick a monitor (see LED vs. LCD)  It all depends on what you want to buy and how much you're willing to spend.  I'd say you could get a very good computer for ~$900-$1100.  You would also be saving some money and getting a fun learning experience.  You can choose all your parts that are on sale or have special offers to save extra money, plus you'll know exactly what in your system!

    I recommend Newegg first for its wide range of products as well as lots of free shipping and no tax in most states.  TigerDirect also has some pretty good deals.

    Putting it together is so easy (not sarcastic, not exaggerated) I'll only give it a paragraph.  Look at the booklet that comes with your motherboard, and every slot should be clearly labeled.  Look at each slot type on your components.  Put each component into the correct slot.  Connect the appropriate power cord to each part.  Wire the power button onto the appropriate part of the motherboard (should be labeled) and the front USB ports of your case (if you have them).  DOUBLE CHECK to make sure it's all OK, then hit the power button!

    If you have the money and you're looking for a new computer, and you want to try something new, I suggest that you build your own computer!

    Saturday, November 27, 2010

    Big and Small, Things and Differences


    Note that the "quadrants" are not the same as the mathematical quadrants, so don't get confused!

    There are 4 types of things summarized in this diagram:
    1. Small things that make a small difference
    2. Big things that make a small difference
    3. Big things that make a big difference
    4. Small things that make a big difference
    Now, as logical people, we can tell which is the "best."  The red square (2) is not very good, the blue squares (1, 3) are OK, and the green square (4) is good.

    We'll approach these in numerical order (with color!):
    1. Surface things.  Things that don't really mean much, but don't take much to do.  Like making your bed. To some, this may mean a lot (and to mothers).  To others, it may not really do anything.  Maybe not making your bed is even better (old article about this)!  Or, using a bookmark instead of putting the book upside-down so that it doesn't damage the spine.  Or, making sure all your pencils are sharpened (might as well, use a mechanical pencil, right?).  The list goes on and on.  Anything that doesn't require much of an effort that doesn't give much in return.  Should you do these?  If you want to.
    2. Nobody likes these.  Things that you work hard for to accomplish not-so-much.  Buying expensive top-of-the-line stuff makes this list.  Especially technology products.  Buy mid-end now because this year's top-notch will be next years mid-range.  For those who have money to burn, that's another story.  Overly meticulous cleaning is also too much, unless you have OCD, are inviting the President to dinner, or are paid to do exactly that.  Another thing is creating a blog that nobody reads (haha... chirp, chirp... silence...).  Point is, avoid this!
    3. Doing big things to get big results.  How about donating $1,000,000 to fight world hunger?  Or going around the world to promote world peace?  It's quite hard to do this for normal people.  I can't say I have done any of this.  I'd say that the people who CAN do this SHOULD do this.  More realistically, how about learning how to play an instrument?  Or how about learning how to program (see Learn to Program!)?
    4. This is what matters most!  This is the main point!  If we take a look around us, we can see so many small things we can do that make a difference!  I'm sure there are many millions of pages on the Internet describing this, but here are a few that stand out to me (in no particular order):
      1. Volunteering.  There are so many places and opportunities for everyone to volunteer and give back to the community. A local hospital or children's camp would welcome volunteers.  Giving a few hours of your time could mean a lot to someone else who needs it a lot more than you do.
      2. Talk to those you are close to.  This doesn't mean just saying "Hi" and "How are you" when you pass them in the hallway.  It means actually carrying on a conversation with them.  It doesn't have to be super-deep or anything.  It just shows that you care (and that they care about you!).
      3. Get some sleep.  Take a nap or go to bed early.  In the modern world, everyone is working so much, nobody has any spare time (but perhaps enough to finish reading this post?) and getting sleep is healthy!
      4. Read a good book.  Or join a book club.  Reading something deep or a classic every once in a while is probably not a bad idea.  Of course we love our sci-fi thrillers and our murder mysteries, but how about a bit of Toni Morrison on racial equality?  These books may seem like a pain to get through at times, but in the end, you will gain a new perspective on life (and you could seem smarter =P )!
      5. Being neat.  Throwing away a candy wrapper instead of dropping it on the floor or spitting out your gum instead of sticking it under the table (super annoying!) is a great idea.  Being neat enough (not to be overdone) can probably improve your efficiency and lift the mood since everything looks neater.  Unless you're like me, and enjoy the messiness.  The problem, however, is that lost things are REALLY lost.  So, take that extra second to throw away your chips bag or RECYCLE useless papers lying around.
      6. Turning off the lights.  This can save energy, the environment, and your costs.  Hmm... if this were a habit, then you would basically be doing good for no effort on your side!  How great!
      7. Don't pretend to be smart.  Sometimes, other people are right, and you're not.  As much as we hate to say it, we're all wrong sometimes.  Don't try to be that guy/gal who knows everything when he/she doesn't.  We all know somebody like this.  It's OK to say that you don't actually know.  Of course, you're an expert at something, and in that subject, others should listen to you!
      8. "Getting out of the Stone Age."  This means being at least somewhat up-to-date with technology.  Of course it's hard to keep up with the ever-changing tech products, but spending a little to update your computer or even your 10-year-old toaster may be a good idea.  When your flickering old CRT monitor is hurting your eyes or your toast is constantly burned, it's probably a warning sign.  This doesn't mean you should go out and buy the latest new gadgets (see Quadrant 2), but you may want to invest in an upgrade (like a new monitor; see LED vs. LCD).  Besides, who doesn't like the new slick feeling of a fast computer and the crunchy taste of well-made toast?
      9. Listen to other people.  Sometimes, all somebody else needs is someone else who will listen.  So, you should try to be that someone else every once in a while (or more frequently).  So I take this opportunity to thank you for listening to me by reading this blog.
      10. Forgive.  This is maybe not an easy thing to do, depending on what happened.  But in small cases, maybe a minor insult or something, it should be easier to forgive the offending party.  Although the other person might not show it, he/she feels much better on the inside.  Think you're being weak apologizing?  Think again.  If it's so difficult, only the strong can do it, right?  Plus, you're being the better man.  Next time, it'll be easier for him/her to forgive you.
    A lot of the small things that make big differences have to do with you helping other people.  Moral of the story?  Keep others in mind!

    Learn to Program!

    Learning how to program is a very useful tool!  Since I do most of my programming in C#, I'm going to recommend it to you.  (Other languages are Visual Basic & Java.  Visual Basic is similar to C# in terms of what they actually do because they both use the .NET framework, but the Java syntax is much close to C# syntax)

    The important things will be red so you know exactly what to look for if you don't want to read through this whole post.

    The first thing we need to do is download and install C#.  Follow this link to get the free Microsoft Visual C# 2010 Express.  Select your language and run the file you downloaded (something like vcs_web.exe).  Now, just follow the instructions on the screen.  Installing it and updating your .NET framework may take a little bit of time, so go have a snack.  Hang out with your friends.  Play a video game.

    When it's finally done installing (maybe even after restarting your computer for the .NET framework), it probably made a shortcut to C# on your desktop.  If it didn't, go into your Start Menu > Programs > Microsoft Visual Studio 2010 Express.  So, open C#.

    It might say it's configuring for your first time.  Again, you have to wait.  But not that long, so go get a drink of water or something.

    When that's done, click the "New Project" button right under the File menu.  In the window that pops up, select Windows Forms Application, which should be the default.  Name it "HelloWorld" and hit "OK".  The window-like thing you see in the middle of your screen is called a "Form" which houses everything you are going to put on it.

    Let's keep it simple and create a simple program that displays "Hello World" when a button is clicked.  Click on your form and go to the Properties window in the bottom-right of your screen.  These are values that change how your Form looks.  First, lets change the "Name" property.  This is how you will reference your Form in your code.  Change the Name field to "frmHelloWorld" (I use the frm prefix for Forms).  Now, lets change the "Text" property, which is what will be displayed on the title bar.  You can put whatever you like here.

    Now that we set up our form, drag a "Button" control from the Toolbox at the right side of your screen onto your Form.  Again, we'll rename this.  Let's name the button "btnMessage" (I use the btn prefix for Buttons).  You can change the "Text" property to whatever you want.  Whatever you choose, it'll be displayed on the button.

    To run your program now, click the forward-pointing green arrow (or press F5 on the keyboard) to debug.  Your Form will appear.  You can move it around.  You can resize it.  You can click the button on it (but nothing happens).  When you're done, close the form to get back to editing your program.

    Although your Form can actually be seen and moved around, it doesn't actually do anything.  Now we need to add an event, which is how your program will interact with your user.  Double-click the button on your Form (when you're back in the editor).  This will add a "Click" event to your form.  Now you're looking at actual code.  Whenever your button is clicked, it will run whatever is between the brackets after "private static void btnMessage_Click...".  We will add a simple line of code:
    MessageBox.Show("Hello World");
    You DO need the semicolon at the end because it means that you're ending a line of code.  If you didn't already guess, this creates a Message Box that pops up with the message "Hello World" when you click on the button.  (I don't know why programmers are so obsessed with "Hello World"... maybe if you wanted to be a rebel, you could say "Greetings Earth")

    Run the program again, and click the button.  If "Hello World" shows up, congratulations, you have created your first program!

    If you're still interested, you should play around with the items in the Toolbox or change the things' properties to see what they do.  If not, you should still give yourself a pat on the back because you took the first step in starting to program!

    Friday, November 26, 2010

    LED vs. LCD

    Actually, a more aptly named title would be LED LCD vs. CCFL LCD.  As Black Friday rolls by and prices are hitting the floor, consumers face the following question when buying monitors (maybe for a multi-monitor setup!): LED backlight or the standard CCFL? CCFL = Cold Cathode Fluorescent Light.  This is currently the standard and basically has lamps and a reflector inside the monitor. LED = Light Emitting Diode.  The most common type has LEDs are placed around the edge of the monitor and a special panel spreads the light evenly across the screen. If you want to find out how these monitors work, I recommend reading some Wikipedia articles: http://en.wikipedia.org/wiki/Liquid_crystal_display http://en.wikipedia.org/wiki/LED-backlit_LCD_television http://en.wikipedia.org/wiki/Cold_cathode http://en.wikipedia.org/wiki/CCFL_inverter Anyway, the more important question is: How does this affect you, the consumer? In my order of least to greatest importance:
    1. LEDs use less power.  A lot of companies use the fact that these new LEDs use less power to promote their product by saying that you're protecting the environment (and saving on power costs).  They're not wrong, but the magnitude is not that great.  You can save around 25% of the power (~15W).  It's really not that much.  I would say that it's better to remember to turn off your lights when you're not going to be using them.
    2. LEDs have a faster response time.  Again, the manufacturers are right, but how much does it actually affect you?  Probably not that much.  Response time is basically what it sounds like: how long it takes the monitor to update the screen based on what you did.  Newer LEDs can usually have a response time of 2ms, a whopping 3ms faster than the normal 5ms monitors.  Most of them are gray-to-gray, meaning not complete changes of pixel color, and I don't think I can tell the difference in those 3ms.  Maybe if you were a totally intense gamer, it would matter.  But not to me.
    3. LEDs are brighter than CCFLs.  Most LEDs are rated at 250 nits brightness, but CCFLs are rated at 300 nits.  However, the LEDs usually appear brighter.  The thing is, this extra brightness probably doesn't matter because most people don't even run their monitors at full brightness.
    4. LEDs are skinnier than CCFLs.  CCFLs have to house those lamps, which take up some space in the back where LEDs have their diodes usually arranged around the edge.  This doesn't matter to me very much because I'm not a fan of great looks, but who wouldn't like a sleek monitor over a bulky one?  But hey, at least the CCFLs are way thinner than the old CRTs!
    5. LEDs do not have a warm-up time.  This one is quite meaningful to me.  I have an LED paired up with an LCD in my dual-monitor setup.  The LED is instantly bright whereas the LCD takes around 30 minutes to reach full brightness.  It's quite annoying during this time to wait for the LCD to heat up its lamps and reach full brightness because it just bothers me that the brightnesses between the two monitors are just so far off.  As a result, I usually leave the monitor on, but it eats some power.  For those who do not use two monitors, it may not matter as much because your eyes would adjust gradually to the increasing brightness.
    6. LEDs have a better contrast ratio.  Because LEDs are lit by the diodes, they can locally dim the screen to pretend to have a better contrast ratio.  The dynamic contrast ratio, or the local dimming, is partly a marketing gimmick.  I would say the static contrast ratio is around 1000:1 for pretty much all monitors right now.  I don't know if I would be able to tell the difference between dynamic ratios of 80000:1 in CCFLs to the 10000000:1 in LEDs.  The one thing that this does help, though is the sharpness of the text.  In my LED-CCFL side-by-side, I would say that the LED is much sharper than the CCFL.  Maybe it's because it has a smaller dot-pitch or maybe it's just better manufactured.  Either way, if the LEDs truly have better sharpness, I think it's much more pleasing to the eye to see sharp, well-defined text rather than slightly fuzzier/grayer text.
    7. LEDs cost more than CCFLs.  You can't get all this good stuff for free (otherwise this post would be pointless)!  Manufacturing LED panels is more expensive, and it reflects on the consumer's side -- you have to pay more.  Currently, the difference is not too great.  Smaller LED monitors are still price comparable to CCFLs, but as you get larger (~23"), the margin increases.  Whereas normal CCFL 23" monitors cost ~$140-150, an LED might be ~$170-180.  This is around a $30 difference, which is 20% of the monitor's cost.
    For those who have a tight budget, maybe it would be better sticking to a CCFL.  For others who have a little extra to spend, maybe it's worth it getting an LED.  It's up to you to decide whether that extra money is worth it for the benefits.  What will you choose?
    Right now, there isn't a clear winner between the two, so "to each his/her own."  (I added the "/her" part to conform to the increasing emphasis on gender equality =P)