|
Minor optimisation tricks like that are something that your compiler should (and probably is) is handling for you.
Write clear and readable code.
|
|
|
|
|
|
Alas, it isn't (but it should!).
|
|
|
|
|
Hi
I need help.
Have drag-and-drop for the components eg. dataset, bindingsource and table adpters.
There is now a default connection string in my app.config file.
The user can now ,using FileOpenDialog on the main form, choose a different database if they want. I simply take this path as a public static string and assign it as the new connectionString. obviously now the dataset must change accordingly. which is does on this main form.
but as soon as i load a child form and still want to use this new dataset obviously, the connection string is changed in the designer code of the tableAdapter.fill() method back to the default connectionstring in the app.config file.
Declaring my connection string as a public static variable worked perfectly in another project where i actually programmatically created my dataset,bindingsource and table adapters.
Is this one of the limitations one has when using drag and drop components??
Please if someone could help me..
|
|
|
|
|
Hi,
I am building a checkers game and I would like to have an option of saving and loading the game. I need to save the game state meaning pictureboxes, arrays, stacks etc... I would be glad to be directed to some article that explains how this could be done.
Thank you
|
|
|
|
|
See, for instance [^].
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Hi Bar3000,
I would generally look down the route of Serialization and DeSerialization of a object(s), that will hold you Games details.
These can be implemented using the ISerializable interface.
Cheers,
Paul
|
|
|
|
|
Perhapse better than implementing ISerializable, which is extra work that really is not neccesary...storing your game state in a separate serializable object that is utilized by your game engine would be a better approach. That way, you put all your game state (i.e. a matrix that maintains the state of each cell on the board, etc.) in a single class. That class can then be serialized without the worry of serializing other game state.
|
|
|
|
|
Hi,
I reckon checkers state is rather limited: to me it is what you see on the board (50 squares being empty, or taken by white, black, white queen, black queen) plus ply (=half move) number.
Internally I would be inclined to store the board state in bitmaps (not the GDI ones!_, being long integers where each bit represents one square. Possible variables might be: white, black, queen, and empty (which would be redundant but might speed up things).
The advantage of bitmaps is they allow you to generate possible moves in parallel by:
- performing shifts, e.g. (newState = oldState << 1) could be a forward move right
- then mask or AND to discard moves to non-empty squares, etc.
So what is keeping you from saving/restoring those few longs?
BTW: I would NEVER use PictureBoxes to render the board of a board game. I'd rather use a single Panel
and paint the squares and pieces myself in its Paint handler.
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
modified on Sunday, June 12, 2011 8:36 AM
|
|
|
|
|
Luc Pattyn wrote: I'd rather use a single Panel
I just use buttons, but I don't need to move anything around.
|
|
|
|
|
Hey where can I get tutorials on VSTO developing add ins for Outlook C# using Visual Studio 2005 Professional??? I have been searching lately and couldn't find any... Any tutorials on the internet??? for a beginneR ...
Thanks
|
|
|
|
|
|
I'm not looking to do a specific thing, rather I would like an introductory tutorial to Outlook VSTO developing.
|
|
|
|
|
Hello all,
I'm in the process of moving the system I work on from C++/MFC/COM to the .NET world. As usual, a lot of legacy code must remain as is client-wise ...
The dilemma I'm facing is the following:
I'm using a sort of home-made IOC framework to instantiate and hold a singleton .NET component. For performance reasons (avoid context switching) I would like to expose it to a native C++ client which till today instantiated the 'good old' COM component (replaced by the .NET component) using CoCreate...
I cannot touch the client's code, and it needs to interact with the .NET component already instantiated.
Any ideas?
Will registering with the ROT do the trick?
Thanks,
Omer
|
|
|
|
|
Hi all,
I want to be much more specific in replacing something in a string. The thing is that the .NET version of String.Replace does not enable one to specify a position.
So is there a String method that can do this?
Example:
string s = "They say he carved it himself...from a BIGGER spoon";
string s2 = "find your soul-mate, Homer.";
s.replace( 32, s2.length(), s2 );
cout << s << endl;
many thanks in advance
Kind regards,
The only programmers that are better C# programmers, are those who look like this -> |
Programm3r
My Blog: ^_^
|
|
|
|
|
.replace will replace substring s3 of string s1 with string s2.
example
string s1 = "Hello Dumb World"; ;
string s2 = "Beautiful";
s2 = s1.Replace("Dumb", s2);
s2 should return "Hello Beautiful World"
|
|
|
|
|
s = s.Insert(32, s2);
If only MySelf.Visible was more than just a getter...
A person can produce over 5 times there own body weight in excrement each year... please re-read your questions before posting
|
|
|
|
|
Brute-force:
s = s.Substring ( 0 , 32 ) + s2 + s.Substring ( 32 + s2.Length ) ;
(Not tested)
|
|
|
|
|
It will replace the text that you specify at the position where that text is found. If you want to replace a piece of string based on location, instead of based on a keyword, use "Substring".
Doin' lots of replacements? Check out Regex
I are troll
|
|
|
|
|
Hi again friends
i have 3 diff forms.
1. BaseForm.( Includes 2 button, Buttons Text "Form1" and "Form2")
2. Form1. (Just inherited BaseForm)
3. Form2. (Just inherited BaseForm)
I know its easy.
I have tried a lot and google a lot but cant find...
Anyway I am asking for help here.
when I run program the base form will appears.If the Button Form1 clicked then
it shows form Form1 and disable Form1 button in that form.
and Hide BaseForm.
same action for Button Form1.
Can anyone show me some code or sample plz.
My other question is
When I click the Right Top Cross button then the Background BaseForm Still running. I want to close all form If I click the cross.
How Can it possible. Plz show mw the way.
Thanks Friends.
|
|
|
|
|
ok when you click button for form 1 or 2, hide the base form then show the desired form with the ShowDialog() method. after which you then show the baseForm again
Then for the disabled buttons you simply close the current form.
soulidentities wrote: I want to close all form If I click the cross
Handle the on close event for each form, then call Application.Exit();
If only MySelf.Visible was more than just a getter...
A person can produce over 5 times there own body weight in excrement each year... please re-read your questions before posting
|
|
|
|
|
Thanks friend for fast reply.
I take the method ShowDialog() from your advice but I cant take the "Simply Close the Current Form"
I need to disable the button. Its my real problem.
I mean when i click the button Form1, it will show Form1 form and hide base form(in the background baseform load newly as well because its being Inherited).
I tried to set click Event on the button in the BaseForm so that when it click it will show form and disable button. But since the BaseForm load freashly it cant not detect the click and the button visible.
Plz some one help me.
Thanks
|
|
|
|
|
ok you lost me now
let me get this straight -
BaseForm has 2 buttons called 'Form1' and 'Form2' only
Form1 has 1 button called 'disable'
Form2 has 1 button called 'disable'
Now...
when you click 'Form1' you want to hide baseForm and show Form1, right?
then when you click 'Disable' on Form1 you want to hide Form1 and then re-show BaseForm, right?
Same for Form2, right?
If only MySelf.Visible was more than just a getter...
A person can produce over 5 times there own body weight in excrement each year... please re-read your questions before posting
|
|
|
|
|
Im sorry i made u confused
You are almost clear with my probs just a lil misunderstood.
Im gonna clear it now.
Form1 has 1 button called 'btnForm1' and text 'Form1'
Form2 has 1 button called 'btnForm2' and text 'Form2'
now when I click 'Form1' I want to hide base form and show Form1
and
Disable the btnForm1 button. Means u cant click btnForm1.
U just can click Form2 button when form1 shows.
I think now I made u clear.
Thanks buddy
|
|
|
|
|
I haven't dealt with an inherited form but I think this achieves what you want - adapt to suit.
using System;
using System.Windows.Forms;
public partial class BaseForm : Form
{
public BaseForm()
{
InitializeComponent();
}
public BaseForm(bool showForm1Button)
: this()
{
btnForm1.Visible = showForm1Button;
}
private void btnForm1_Click(object sender, EventArgs e)
{
BaseForm newBaseForm = new BaseForm(false);
newBaseForm.FormClosing += new FormClosingEventHandler(newBaseForm_FormClosing);
newBaseForm.Show();
Hide();
}
void newBaseForm_FormClosing(object sender, FormClosingEventArgs e)
{
Close();
}
}
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)
|
|
|
|