|
Okay, so split it up in seperate variables, and afterwards check them for null?
so example:
if (webBrowser1 == null)
{
myLabel.Text = "Webbrowser is null";
}
And do that with all the objects i use for getting the source ?
|
|
|
|
|
Yes. Sooner or later you'll find the null variable. Do you just need to get the entire source code of a web page?
|
|
|
|
|
Yes I just need the entire source code, from the page the webclient browser is showing in the application..
I did this now, maybe that helps?
if (webBrowser1 == null)
{
write2log("Webbrowser object null error");
Wait(6000);
waitLoading();
}
if (webBrowser1.Document == null)
{
write2log("Webbrowser object null error 1");
Wait(6000);
waitLoading();
}
if (webBrowser1.Document.Window == null)
{
write2log("Webbrowser object null error 2");
Wait(6000);
waitLoading();
}
if (webBrowser1.Document.Window.Frames[2] == null)
{
write2log("Webbrowser object null error 3");
Wait(6000);
waitLoading();
}
if (webBrowser1.Document.Window.Frames[2].Document.Body.InnerHtml == null)
{
write2log("Webbrowser object null error 4");
Wait(6000);
waitLoading();
}
|
|
|
|
|
So which error message do you get?
|
|
|
|
|
I have a problem to under stand how delegates work (mainly because of where you declare it, i saw some webs and every web declared it in another place)
do i need to learn inheritance first?
My Code is:
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 WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Label score = new Label();
public PictureBox[,] checkers_board = new PictureBox[8, 8];
public string[,] checkers_value = new string[8, 8];
public delegate void HandleBoardClick (object sender, int x, int y);
public event HandleBoardClick handleBoardClick;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
ImageList imageList1 = new ImageList();
imageList1.Images.Add(Image.FromFile("Images\\silver.jpg"));
imageList1.Images.Add(Image.FromFile("Images\\gold.jpg"));
this.Text = "Dins Checkers";
this.Width = 600;
this.Height = 600;
Image loadGold = imageList1.Images[0];
Image loadSilver = imageList1.Images[1];
int goldEaten = 0;
int silverEaten = 0;
for (int i = 0; i < checkers_board.GetLength(0); i++)
{
for (int j = 0; j < checkers_board.GetLength(1); j++)
{
checkers_board[i, j] = new PictureBox();
if (i < 3)
{
if ((i % 2 == 0 && j % 2 == 0) || (i % 2 == 1 && j % 2 == 1))
{
checkers_board[i, j].BackgroundImage = loadGold;
checkers_value[i, j] = "gold-reg";
}
}
else if (i > 4)
{
if ((i % 2 == 1 && j % 2 == 1) || (i % 2 == 0 && j % 2 == 0))
{
checkers_board[i, j].BackgroundImage = loadSilver;
checkers_value[i,j] = "silver-reg";
}
}
else
{
checkers_value[i,j] = "none";
}
checkers_board[i, j].BorderStyle = BorderStyle.Fixed3D;
if ((i % 2 == 0 && j % 2 == 0) || (i % 2 == 1 && j % 2 == 1))
{
checkers_board[i, j].BackColor = Color.White;
}
if (checkers_board[i, j].BackColor != Color.White)
{
checkers_board[i, j].BackColor = Color.Black;
}
checkers_board[i, j].Top = 30 + 55 * i;
checkers_board[i, j].Width = 61;
checkers_board[i, j].Height = 53;
checkers_board[i, j].Left = 30 + 65 * j;
this.Controls.Add(checkers_board[i, j]);
}
}
score.Text = "תוצאה: זהובים אכולים- " + goldEaten.ToString() + " כסופים אכולים- " + silverEaten.ToString();
score.Top = 510;
score.Left = 250;
score.Width = 500;
this.Controls.Add(score);
for (int i = 0; i < checkers_board.GetLength(0); i++)
{
for (int j = 0; j < checkers_board.GetLength(1); j++)
{
if (Control.Click != null)
{
x = i;
y = j;
checkers_board[i, j].Click += new HandleBoardClick(HandleBoardClick1);
}
}
}
}
private void HandleBoardClick1(object sender, EventArgs e, int x, int y)
{
for (int i = x - 1; i <= x + 1; i++)
{
for (int j = y - 1; j <= y + 1; j++)
{
if (checkers_value[i, j] == "none" && checkers_board[i, j].BackColor == Color.White)
{
checkers_board[i, j].BackColor = Color.Green;
}
}
}
}
}
}
what i want to do is: for each PictureBox in checkers_board if an Click accord then HandleBoardClick1 will be called and with his parameters
thanks for the helpers
|
|
|
|
|
Hi,
1.
you can't change the signature of a .NET delegate, so a Control.Click event will trigger a void XXX_Click(object sender, System.EventArgs e) and nothing else.
Now your problem seems to be you want to share the click handler for all PBs so you need to identify which PB got clicked. That is what the "object sender" is for: cast it to a PB and you have the reference to the PB.
2.
I do have a lot of suggestions for you:
2a. if ((i % 2 == 0 && j % 2 == 0) || (i % 2 == 1 && j % 2 == 1)) ... can be simplified to if ((i+j) % 2 == 0) ...
2b. checkers_board.GetLength(0) is a bit ugly; why not define a constant, say const int BOARDSIZE=8; and then use that everywhere (in the array declarations, and in all the for loops).
2c. I don't see how checkers_value is going to be useful.
2d. I would separate the game logic from the UI, i.e. keep the board state in one data structure (maybe an array of ints), let the game run without caring about the UI, then have a Paint method that takes the board and paint it. That way, if you decide to do the UI differently, you don't have to change all the code everywhere ("separation of concerns").
2d. you might consider a little enum with four values: WHITE, BLACK, EMPTY, UNUSED (and probably have four images to reflect that). Testing a square for a particular int or enum value will be easier and faster than comparing colors all the time.
3.
Some more advanced stuff:
3a. I avoid using two-dimensional arrays; a chess/checkerlike game can be handled perfectly well using a one-dimensional array. The benefit is less code, faster execution, at the expense of some getting used to. Checkerlike moves are then executed by adding +9, +7, -7 or -9 to the current position instead of (+1,+1), (+1,-1), (-1,+1), (-1,-1).
3b. I tend to add extra squares around the border, with a special value, so the squares next to the border (where moves are limited) don't need special code: just checking the destination square is EMPTY will prevent a piece to wrap from one side to the other.
3c. Very advanced: There are special gaming techniques, often called "bit vectors", where all squares are represented by the individual bits of a single variable (ideal for chess, 64 bits fit in a long). This prohibits the virtual border squares but OTOH it makes it possible to generate a lot of moves in parallel (by performing shift and AND operations). Not beginners stuff though, needed however if you want to achieve the game strength of commercial games.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
I am using an unmanaged DLL which will be accessed from a Windows application.
After I have first called a function within it, will it stay in memory until the form closes?
There are a number of variables within it I need to be able ot rely on.
Thanks.
Elaine
modified on Thursday, May 21, 2009 2:18 PM
|
|
|
|
|
It'll stay in memory as part of your app's process until the app closes, not the form.
|
|
|
|
|
Thanks Dave, that is what I was hoping for.
|
|
|
|
|
Apparently someone didn't agree with you, you got my 5 to compensate a bit.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
And mine just to spite the uni-voter
|
|
|
|
|
Ditto
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Hi
i want to create a sequantial workflow app (without wf), i'm looking for what tables is needed to implement this, for example we need some tables like workflowTypes, workflowSteps, workflowActivities, ... .
can anybody help me and have experience in this issue ?
thanks
|
|
|
|
|
Hi I was just wondering I made a component off an example on this site. Now I wish to post it for everyone to use. But how would I do that. I’m not that talkative person so I can’t really write about it so much. What would be the best cause of action???
|
|
|
|
|
Writing an article is about the best option you have. Or post it on your own personal blog.
|
|
|
|
|
If you want, have a go at writing an article in plain text, then drop me an email from the link at the bottom of this message. I'll mail you back and you can send me the code and text. I'll see if there's anything I can do to make it 'article worthy' for you.
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
|
|
|
|
thank you i will see if i have time for it tomorrow.. do i need to post a link in the article that helped me?
|
|
|
|
|
I wouldn't post a link in the other article's forum as it might be seen as a 'hijacking' attempt, unless the other article is no longer supported by the author and you are offering to take over support.
Definately make sure there's in link in your article to the original and explain what's different/improvements etc.
Drop the author of the other article a private email letting him know what you've done so he can edit his article to link to yours if he wants.
These aren't rules, just my personal opinion.
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
|
|
|
|
Hello I'm using the below code to color a picture but it is pretty slow is there a way to do it faster?
Thanks in advance.
<br />
Bitmap Turn(Bitmap pic)<br />
{<br />
Bitmap newpic = new Bitmap(pic.Width, pic.Height);<br />
for (int i = 0; i < pic.Width; i++)<br />
{<br />
for (int j = 0; j < pic.Height; j++)<br />
{<br />
Color color = pic.GetPixel(i, j);<br />
newpic.SetPixel(i, j, Color.FromArgb(123, 46, 125));<br />
}<br />
}<br />
return newpic;<br />
}<br />
|
|
|
|
|
Why are you retrieving the color from pic when you don't use it?
Here
Color color = pic.GetPixel(i, j); <=============================== this never gets used.
newpic.SetPixel(i, j, Color.FromArgb(123, 46, 125));
But if your newpic is to be all one color, look up the Graphics class, and the Fill method of that class.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Search the articles for "Image processing for dummies" and you'll find a series of articles that covers just what you're looking for.
|
|
|
|
|
Hi,
1.
an easy win is to replace pic.Height by a variable that gets initialized only once.
2.
for a fixed color, there are better ways, as Henry already mentioned. Here is one:
Graphics g=Graphics.FromImage(newpic);
g.FillRectangle(...);
g.Dispose();
3. the general solution for maximum performance is using pointers, avoiding GetPixel/SetPixel since these methods will perform boundary checks and coordinate conversions for each individual pixel.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
I have realised that I made a typo, had a brain fart, in my previous post.
I should have said
If it is going to be one color investigate the Graphics class and the Clear method of that class. Although the various Fill methods are good to know.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Thank you all for your good answers.
|
|
|
|
|
Hi,
Pop3 and Smtp work the sameway.. one sends a string message to the server (eg: HELO, USER user, PASS pass) and the server responses (eg. 250 Hello and welcome)
Is there any standard class for this type of communication? something simple like
+Connect()
+Write(s)
+LastResponse()
Because i'm not getting good results ..though i'm trying to communicate with gmail's pop and smtp, so maybe i'm failing with the SSL thing..
I'm having trouble with the Writing and Response,
public string SendMessage(string message)
{
ASCIIEncoding asciiEncoder = new ASCIIEncoding();
byte[] WriteBuffer = new byte[1024]; // 1 KB
WriteBuffer = asciiEncoder.GetBytes(message);
NetworkStream stream = cl.GetStream(); // cl is a TcpClient
stream.Write(WriteBuffer, 0, WriteBuffer.Length);
// Get response after message
return Response();
}
And my response method is:
public string Response()
{
byte[] serverbuffer = new Byte[1024]; //1 KB
int count = ns.Read(serverbuffer, 0, 1024);
if (count == 0)
{
return "";
}
return Encoding.ASCII.GetString(serverbuffer, 0, count);
}
|
|
|
|
|