.NET Thread

M1kkelZR

Active Member
You are a good programmer,but THIS was hard for you???
Wow...and I thought I am weird lol xD

yeah its weird. i can easily make server based games and console's but this just got me by suprise. good thing i can always google but this time google didnt help lol
 

spider_007

New Member
This is my collide-function, i'm making a space invaders...
It's working, but I want a better function for when they hit each other
(userbullet-enemy) or (enemybullet-user)
one = the bullet of either user/bullet
two = user/enemy
I use this method for checking both.
I'd like a more effective way to calculate if a bullet has reached a player,
some people told me to do it with rectangles, but could anyone give an example of that, please?

thanks, spider

Code:
private bool Collides(Sprite one, Sprite two)
        {
            if (one == null || two == null)
            {
                return false;
            }
            else if
            (
                two.X < one.X
                && (two.X + two.Width) > (one.X + one.Width)
                && two.Y < one.Y
                && (two.Y + two.Height) > (one.Y + one.Height)
            )
            {
                return true;
            }
            else
            {
                return false;
            }
        }
 

Cromewell

Administrator
Staff member
What you are trying to do with box collision models is draw a box around your objects (player, targets, bullets), then check if the any of the boxes overlap. If so, it's a hit.

From your code snippet, it looks like you are on the right track. Sprites are basically a box already so you just need to see if they overlapped.
 

spider_007

New Member
What you are trying to do with box collision models is draw a box around your objects (player, targets, bullets), then check if the any of the boxes overlap. If so, it's a hit.

From your code snippet, it looks like you are on the right track. Sprites are basically a box already so you just need to see if they overlapped.

Yeah I made a Rectangle class and was able to draw them around the players, but the bullets are more difficult and I heard there was a Intersect-method available as well, I just started programming this month, so I'm still at the basic-stuff,

anyways, thanks for your reply
 

Cromewell

Administrator
Staff member
There may be something like intersect, I'm not to big on .net. I can read the code, but I don't really know any objects/default methods off hand like I would with Java.

It should be the same to draw a box over the bullet, you just need to move the box with it. You'll want to be careful about speed though, make sure that if the bullet moves so fast that it could pass through another box in a single update that you check the 'hit range.'
 
VB.NET Question

How can I create a class in Visual Basic .Net 4.5 2010 so that it says something like:
Code:
Private Class Form1
Private Sub Label1.formload()
Lable1.text = ProcessorName()
End Sub
End Class

So that when the form loads, the label's text changes to the processor name like "i3-2330M"
 

janrob

New Member
Never used VB.NET but in VB6 there is an event called form_load and there you put the start up code.
 

Cromewell

Administrator
Staff member
Ok, well lets start there. Your code to change the label's text is fine, assuming your ProcessorName function returns a string.

Are you trying to read hardware strings to determine the name of the processor? I think something like this will do it.
Code:
moSearch = New Management.ManagementObjectSearcher("Select *
from Win32_Processor")
moReturn = moSearch.Get
For Each mo In moReturn
 sCPManufacturer = mo("Manufacturer").ToString.Trim
 sCPName = mo("Name").ToString.Trim
 sCPSerialNo = mo("ProcessorID").ToString.Trim
next
 
Ok, well lets start there. Your code to change the label's text is fine, assuming your ProcessorName function returns a string.

Are you trying to read hardware strings to determine the name of the processor? I think something like this will do it.
Code:
moSearch = New Management.ManagementObjectSearcher("Select *
from Win32_Processor")
moReturn = moSearch.Get
For Each mo In moReturn
 sCPManufacturer = mo("Manufacturer").ToString.Trim
 sCPName = mo("Name").ToString.Trim
 sCPSerialNo = mo("ProcessorID").ToString.Trim
next

I will try that :) Do I put this in as its own sub? It is vb.net right? Would it be better to convert to a C of somesort like C#, C#.net or C++ as I am new to this.#

No...I am guessing that this is C#, as VB.NET gives me loads of errors, if you wait until saturday, I can download C#.NET :) Would you be willing to help teach me to use it?
 
Last edited:

Cromewell

Administrator
Staff member
It should work in VB, Unfortunately, I haven't built this myself as I don't have a vm with a dev environment for .net right now. If you have option explicit on make sure the variables are dim'd.

It's possible that there's an addin module missing from the project, I'll see what I can find, or if there's an alternative.

What errors are you getting?
 
It should work in VB, Unfortunately, I haven't built this myself as I don't have a vm with a dev environment for .net right now. If you have option explicit on make sure the variables are dim'd.

It's possible that there's an addin module missing from the project, I'll see what I can find, or if there's an alternative.

What errors are you getting?

I have no idea:L I am new and know nothing about what this means. The best I have been able to program is this:
Version 1: http://www.mediafire.com/?8dnav7neq6ll72j
Version 2: http://www.mediafire.com/?zcxrd8skdvnfqnv

Its a disk cleanup...I want to expand on it so it shows CPU usage with a performance bar, RAM usage with a performance bar, the CPU Name, Model, and the amount of RAM.

I know nothing about Visual Basic, I started a week ago, and don't know where to start :confused:

The version 2 crashes on all x86_32 systems it seems, it crashed on all the school computers (which I guess are 32 bit as they used to have XP on, or only have 4gb ram, and had Ubuntu Originally on it.) and my netbook (which is x86_32), and my other Laptop (that is running Windows 7 x86_32, even though it is a x86_64 processor). It only seems to work on my Toshiba which is 64bit, and on Spirit and Smilemans computers, which I guess are 64bit.:angry: Its really frustrating as Version 1 works on them, Version 2 is the same code, but just a different layout of the design, and a code to fade in and out the forms when the value of focus changes. :gun:

Be interesting to know if you have any ideas, as I have exhausted my limited knowledge :(
 

M1kkelZR

Active Member
Hey guys, I'm doing a programming thing for college in C#. I'm nearly done. I have to use Databindings, DataSources etc and it has to be finished tomorrow.
This is annoying me, I have a picturebox where I import a picture. I save the record but it doesnt save the picture to that record. It keeps the picture for every record. Also when I restart the program the picture doesn't appear.

This is my code now:

Code:
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;
using System.Diagnostics;
using System.Threading;
using System.IO;

namespace CDForm
{
    public partial class Form1 : Form
    {

        private string fileName = string.Format(@"{0}\teams.xml", Application.StartupPath);

        BindingSource Verzameling = new BindingSource();
        CDverzameling Teamset = new CDverzameling();


        public Form1()
        {
            InitializeComponent();
            MyInitialize();

            backgroundWorker1.RunWorkerAsync();

            Teamset.ReadXml(fileName);
            this.FormClosing += new FormClosingEventHandler(Form1_FormClosing);
        }

        void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            Verzameling.EndEdit();
            Teamset.WriteXml(fileName);
        }

        private void MyInitialize()
        {

            Verzameling.DataSource = Teamset.Tables["Teams"];

            this.txtTeamName.DataBindings.Add(new Binding("Text", Verzameling, "TeamName"));
            this.txtMember.DataBindings.Add(new Binding("Text", Verzameling, "Member"));
            //this.txtWeapon.DataBindings.Add(new Binding("Text", Verzameling, "Weapon"));
            this.txtSkill.DataBindings.Add(new Binding("Text", Verzameling, "Skill"));
            this.pictureBox1.DataBindings.Add(new Binding("ImageLocation", Verzameling, "Weapon"));
            //this.cmbChooseWeap.DataBindings.Add(new Binding("SelectedValue", Verzameling, "Weapon"));

            this.Teamsbn.BindingSource = Verzameling;
        }

        private void btnToon_Click(object sender, EventArgs e)
        {
            Process.Start("Notepad.exe", fileName);
        }


        private void btnSave_Click(object sender, EventArgs e)
        {
            Teamset.WriteXml(fileName);
        }

        private void bindingNavigatorAddNewItem_Click(object sender, EventArgs e)
        {
            this.Activate();
        }

        private void btnForm2_Click(object sender, EventArgs e)
        {
            Form2 f2 = new Form2();
            f2.Show();
            this.Hide();
        }

        private void picBut_Click(object sender, EventArgs e)
        {
            OpenFileDialog dlg = new OpenFileDialog();

            dlg.Title = "Choose Gun For Correct Class.";
            dlg.InitialDirectory = "Guns/";

            if (!Directory.Exists(initialDirectory))
            {
                
                if (initialDirectory != "Guns/")
                {
                   // MessageBox.Show("Not the Right Directory. Please Use the Guns folder in this project.");
                    dlg.Dispose();
                }
                else
                {
                    // Do nothing
                }
            }
            
            if (dlg.ShowDialog() == DialogResult.OK)
            {
                this.pictureBox1.Image = new Bitmap(dlg.OpenFile());
            }
            dlg.Dispose();
        }

        public string initialDirectory { get; set; }
    }
}

Basically I just need help to save the image and change for each record. So if anyone can help that would be awesome :)
 

Cromewell

Administrator
Staff member
Hey guys, I'm doing a programming thing for college in C#. I'm nearly done. I have to use Databindings, DataSources etc and it has to be finished tomorrow.
This is annoying me, I have a picturebox where I import a picture. I save the record but it doesnt save the picture to that record. It keeps the picture for every record. Also when I restart the program the picture doesn't appear.

This is my code now:

Code:
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;
using System.Diagnostics;
using System.Threading;
using System.IO;

namespace CDForm
{
    public partial class Form1 : Form
    {

        private string fileName = string.Format(@"{0}\teams.xml", Application.StartupPath);

        BindingSource Verzameling = new BindingSource();
        CDverzameling Teamset = new CDverzameling();


        public Form1()
        {
            InitializeComponent();
            MyInitialize();

            backgroundWorker1.RunWorkerAsync();

            Teamset.ReadXml(fileName);
            this.FormClosing += new FormClosingEventHandler(Form1_FormClosing);
        }

        void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            Verzameling.EndEdit();
            Teamset.WriteXml(fileName);
        }

        private void MyInitialize()
        {

            Verzameling.DataSource = Teamset.Tables["Teams"];

            this.txtTeamName.DataBindings.Add(new Binding("Text", Verzameling, "TeamName"));
            this.txtMember.DataBindings.Add(new Binding("Text", Verzameling, "Member"));
            //this.txtWeapon.DataBindings.Add(new Binding("Text", Verzameling, "Weapon"));
            this.txtSkill.DataBindings.Add(new Binding("Text", Verzameling, "Skill"));
            this.pictureBox1.DataBindings.Add(new Binding("ImageLocation", Verzameling, "Weapon"));
            //this.cmbChooseWeap.DataBindings.Add(new Binding("SelectedValue", Verzameling, "Weapon"));

            this.Teamsbn.BindingSource = Verzameling;
        }

        private void btnToon_Click(object sender, EventArgs e)
        {
            Process.Start("Notepad.exe", fileName);
        }


        private void btnSave_Click(object sender, EventArgs e)
        {
            Teamset.WriteXml(fileName);
        }

        private void bindingNavigatorAddNewItem_Click(object sender, EventArgs e)
        {
            this.Activate();
        }

        private void btnForm2_Click(object sender, EventArgs e)
        {
            Form2 f2 = new Form2();
            f2.Show();
            this.Hide();
        }

        private void picBut_Click(object sender, EventArgs e)
        {
            OpenFileDialog dlg = new OpenFileDialog();

            dlg.Title = "Choose Gun For Correct Class.";
            dlg.InitialDirectory = "Guns/";

            if (!Directory.Exists(initialDirectory))
            {
                
                if (initialDirectory != "Guns/")
                {
                   // MessageBox.Show("Not the Right Directory. Please Use the Guns folder in this project.");
                    dlg.Dispose();
                }
                else
                {
                    // Do nothing
                }
            }
            
            if (dlg.ShowDialog() == DialogResult.OK)
            {
                this.pictureBox1.Image = new Bitmap(dlg.OpenFile());
            }
            dlg.Dispose();
        }

        public string initialDirectory { get; set; }
    }
}

Basically I just need help to save the image and change for each record. So if anyone can help that would be awesome :)
I see you binding the image but does your database have the appropriate storage types to handle an image?
I have no idea:L I am new and know nothing about what this means. The best I have been able to program is this:
Version 1: http://www.mediafire.com/?8dnav7neq6ll72j
Version 2: http://www.mediafire.com/?zcxrd8skdvnfqnv

Its a disk cleanup...I want to expand on it so it shows CPU usage with a performance bar, RAM usage with a performance bar, the CPU Name, Model, and the amount of RAM.

I know nothing about Visual Basic, I started a week ago, and don't know where to start :confused:

The version 2 crashes on all x86_32 systems it seems, it crashed on all the school computers (which I guess are 32 bit as they used to have XP on, or only have 4gb ram, and had Ubuntu Originally on it.) and my netbook (which is x86_32), and my other Laptop (that is running Windows 7 x86_32, even though it is a x86_64 processor). It only seems to work on my Toshiba which is 64bit, and on Spirit and Smilemans computers, which I guess are 64bit.:angry: Its really frustrating as Version 1 works on them, Version 2 is the same code, but just a different layout of the design, and a code to fade in and out the forms when the value of focus changes. :gun:

Be interesting to know if you have any ideas, as I have exhausted my limited knowledge :(
Sorry I meant to look at this earlier but forgot. I'll try to get to it when I get home. I can't get on mediafire here.
 

M1kkelZR

Active Member
Yeah I've got the attribute to use an Image and the ImageLocation. Now it saves the picture in the record but when I start it up again it deletes it. Also can't change to a different picture because it changes it on every record lol. No clue whats going on

EDIT: Never mind, I figured it out :D I forgot about the whole "It needs to write a path to the XML database" part :p
 
Last edited:

Cromewell

Administrator
Staff member
I have no idea:L I am new and know nothing about what this means. The best I have been able to program is this:
Version 1: http://www.mediafire.com/?8dnav7neq6ll72j
Version 2: http://www.mediafire.com/?zcxrd8skdvnfqnv

Its a disk cleanup...I want to expand on it so it shows CPU usage with a performance bar, RAM usage with a performance bar, the CPU Name, Model, and the amount of RAM.

I know nothing about Visual Basic, I started a week ago, and don't know where to start :confused:

The version 2 crashes on all x86_32 systems it seems, it crashed on all the school computers (which I guess are 32 bit as they used to have XP on, or only have 4gb ram, and had Ubuntu Originally on it.) and my netbook (which is x86_32), and my other Laptop (that is running Windows 7 x86_32, even though it is a x86_64 processor). It only seems to work on my Toshiba which is 64bit, and on Spirit and Smilemans computers, which I guess are 64bit.:angry: Its really frustrating as Version 1 works on them, Version 2 is the same code, but just a different layout of the design, and a code to fade in and out the forms when the value of focus changes. :gun:

Be interesting to know if you have any ideas, as I have exhausted my limited knowledge :(

I can't look through the code in those exes but my guess is the compile method is the problem. If they are compiled for a particular architecture, ie x86-64, it won't work on a 32 bit system. A 32 bit compiled version should work on either version of windows.
 

S.T.A.R.S.

banned
I have no idea:L I am new and know nothing about what this means. The best I have been able to program is this:
Version 1: http://www.mediafire.com/?8dnav7neq6ll72j
Version 2: http://www.mediafire.com/?zcxrd8skdvnfqnv

Its a disk cleanup...I want to expand on it so it shows CPU usage with a performance bar, RAM usage with a performance bar, the CPU Name, Model, and the amount of RAM.

I know nothing about Visual Basic, I started a week ago, and don't know where to start :confused:

The version 2 crashes on all x86_32 systems it seems, it crashed on all the school computers (which I guess are 32 bit as they used to have XP on, or only have 4gb ram, and had Ubuntu Originally on it.) and my netbook (which is x86_32), and my other Laptop (that is running Windows 7 x86_32, even though it is a x86_64 processor). It only seems to work on my Toshiba which is 64bit, and on Spirit and Smilemans computers, which I guess are 64bit.:angry: Its really frustrating as Version 1 works on them, Version 2 is the same code, but just a different layout of the design, and a code to fade in and out the forms when the value of focus changes. :gun:

Be interesting to know if you have any ideas, as I have exhausted my limited knowledge :(

To read informations from the hardware like amount of RAM,CPU name,model and everything else you would like,I recommend you to use Managed Object Searcher class.
Of course you will need to add the following namespace:

using System.Management;

Here is an example of getting the total amount of RAM in bytes:

ManagementObjectSearcher mos1=new ManagementObjectSearcher("SELECT * FROM WIN32_PHYSICALMEMORY");
foreach(ManagementObject mo1 in mos1.Get())
{
MessageBox.Show(mo1.GetPropertyValue("CAPACITY").ToString());
}



By the way I am SOOOOO bored right now lol xD
 
Last edited:
Top