How to make an avatar viewer using C#

XPGProgrammer Feb 23, 2013

  1. XPGProgrammer

    XPGProgrammer Newbie
    25/47

    Joined:
    Jan 2, 2013
    Messages:
    802
    Likes Received:
    214
    Trophy Points:
    0
    Gender:
    Male
    Location:
    Canada
    Console:
    Xbox
    Hello guys, I thought it would help some people that are still learning. An avatar viewer is pretty basic but funny to use.

    Step 1:
    You'll need to open Microsoft Visual Studio and select C# as the language.

    Step 2:
    You'll need to choose "Windows Form Application" and name it as "Avatar Viewer" if you want to.
    [​IMG]

    Step 3:
    Once you choosed the windows form application and you clicked okay, wait until the code is fully loaded and then add a groupBox called "Search". And add to it a label called "Gamertag:" and put a textBox to be able to type the gamertag. After that, add a button called "Begin searching". It should look like this:
    [​IMG]

    Step 4:
    Add another groupBox but this time, call it "Avatar" and add to it a pictureBox. There should be a little arrow in top right. Click on the little arrow and click "Dock in Parent Container.". Then change the "SizeMode" to "CenterImage". It should look like this:
    [​IMG]


    Step 5:
    Click on the button called "Begin searching".

    Step 6:
    Add the following code to it:

    try
    {
    pictureBox1.ImageLocation = "http://avatar.xboxlive.com/avatar/"
    + textBox1.Text + "/avatar-body.png#.USkt3x02aIM";
    }
    catch
    {
    MessageBox.Show("Your avatar couldn't be retrieved");
    }




    If the gamertag isn't available, it will pop up a little window saying "Your avatar couldn't be retrieved".


    If it works correctly, it should look like this:
    [​IMG]


    Thanks and I hope that it helps you!

    Off topic: Major Nelson has a pretty nice avatar :p.
     
  2. XPGProgrammer

    XPGProgrammer Newbie
    0/47

    Joined:
    Jan 2, 2013
    Messages:
    802
    Likes Received:
    214
    Trophy Points:
    0
    Gender:
    Male
    Location:
    Canada
    Console:
    Xbox
    If you have any question about this then feel free to hit me up. But anyways, I doubt you guys will have questions about this lol..
     
  3. begallegal1

    begallegal1 Medicine Man Lifetime Gold TeamXPG
    235/282

    Joined:
    Oct 31, 2011
    Messages:
    3,694
    Likes Received:
    3,128
    Trophy Points:
    235
    Gender:
    Male
    Location:
    In a Field of Green
    Console:
    Xbox
    will probably implement this in a few tools for fun , very cool programmer! great share ;)
     
  4. XPGProgrammer

    XPGProgrammer Newbie
    0/47

    Joined:
    Jan 2, 2013
    Messages:
    802
    Likes Received:
    214
    Trophy Points:
    0
    Gender:
    Male
    Location:
    Canada
    Console:
    Xbox
    You're welcome Begal!
     
  5. Co

    CoDiWin Member BANNED
    95/188

    Joined:
    Jun 24, 2012
    Messages:
    1,014
    Likes Received:
    186
    Trophy Points:
    95
    Gender:
    Male
    Console:
    Xbox
    cant seem to find c#?
    [​IMG]
    &
    [​IMG]
     
  6. begallegal1

    begallegal1 Medicine Man Lifetime Gold TeamXPG
    235/282

    Joined:
    Oct 31, 2011
    Messages:
    3,694
    Likes Received:
    3,128
    Trophy Points:
    235
    Gender:
    Male
    Location:
    In a Field of Green
    Console:
    Xbox
    That's because you only have Visual Basic (VB) , you'll need to upgrade to Visual Studio to add the other languages ;)
     
  7. Bu

    Bullet Guest

    Nice clean tutorial Programmer thanks for the share.
     
  8. Promotion

    Promotion Banned
    0/47

    Joined:
    Feb 18, 2013
    Messages:
    231
    Likes Received:
    142
    Trophy Points:
    0
    Console:
    Xbox
    For VB.NET its...
    [​IMG]


    Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    PictureBox1.ImageLocation = "http://avatar.xboxlive.com/avatar/" + TextBox1.Text + "/avatar-body.png#.USkt3x02aIM"
    End Sub
    End Class

    great tutorial!
     
  9. begallegal1

    begallegal1 Medicine Man Lifetime Gold TeamXPG
    235/282

    Joined:
    Oct 31, 2011
    Messages:
    3,694
    Likes Received:
    3,128
    Trophy Points:
    235
    Gender:
    Male
    Location:
    In a Field of Green
    Console:
    Xbox
    Since this is XPG and nothing can go unmodded :p
    here's couple more basic things you can do in this or other programs to save some hassle of typing in the info every time ;)

    Add a .txt file to your project named "Gamertag.txt" and set it's properties to "copy always"

    // Add this to stream info from txt file
    using System.IO;

    // create a link label and make it open your txt for easy editing
    private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
    {
    System.Diagnostics.Process.Start(Application.StartupPath + "\\Gamertag.txt");
    }
    //Add to the form load ,what and where the file is and where to stream it
    private void Form1_Load(object sender, EventArgs e)
    {
    //Add this so your gamer tag loads from the .txt file
    textBox1.Text = System.IO.File.ReadAllText(Application.StartupPath + "\\Gamertag.txt");
    using (FileStream fileStream = File.OpenRead(Application.StartupPath + "\\Gamertag.txt"))
    using (StreamReader streamReader = new StreamReader(fileStream))
    {
    string fileContent = streamReader.ReadToEnd();

    textBox1.Text = fileContent;
    }
    }


    the result will auto fill your text box upon opening ,and easily edit your .txt file if needed
    [​IMG]
     
  10. XPGProgrammer

    XPGProgrammer Newbie
    0/47

    Joined:
    Jan 2, 2013
    Messages:
    802
    Likes Received:
    214
    Trophy Points:
    0
    Gender:
    Male
    Location:
    Canada
    Console:
    Xbox
    Thanks for this :) By the way, could you give me the little XPG image in the corner so I can use it for my future tools?
     
  11. Coder123

    Coder123 Finnish Modder XPG Developer TeamXPG
    105/188

    Joined:
    Jan 21, 2012
    Messages:
    1,954
    Likes Received:
    717
    Trophy Points:
    105
    Gender:
    Male
    Location:
    Finland
    Console:
    Xbox
    Simple and clean code! :)
     
  12. XPGProgrammer

    XPGProgrammer Newbie
    0/47

    Joined:
    Jan 2, 2013
    Messages:
    802
    Likes Received:
    214
    Trophy Points:
    0
    Gender:
    Male
    Location:
    Canada
    Console:
    Xbox
    Thank you my brother!
     
  13. Narianor

    Narianor Cookie Lover BANNED
    25/47

    Joined:
    Mar 27, 2013
    Messages:
    378
    Likes Received:
    89
    Trophy Points:
    25
    Gender:
    Male
    Location:
    Outside your window
    Console:
    Xbox
    Thanks for this.
    Mine came out like crap everytime I tried to do it myself so I succumbed to your C# code.
    [​IMG]
     

Share This Page

Close