|
Hi Roger,
I'm into nested UserControls. I'll assume that what I say here is easily "tranposed" from WinForms to WPF, while being not entirely sure that's true.
The case of 90 UserControls (80 tile controls, and, in this case, ten "row of tiles" containers) would not worry me the least bit in terms of performance ... in WinForms.
I'd start with your basic Usercontrol, 'TheTile,' and make it expose public properties such as its (invariant) unique number, a boolean for its current "state:" selected or unselected.
Inside TheTile, I'd use a a Label control, rather than a button, which would contain the number, and I'd create Public get/set properties to set the number.
I'd then build a 'RowOfTiles' UserControl each of which would contain ten instances of the 'TheTile:' in the 'Load event of RowOfTiles, and add them to the RowOfTiles instance Control Collection: by setting the Dock property of TheTile to Dock.Right, you get automatic proper horizontal alignment/order.
Then in the Form/Window Load event, I'd for-loop instantiate ten instances of the RowOfTiles control, and add them to the Control collection of the Panel container on the Form. Again, using Dock set to Dock.Bottom will give you automatic proper vertical alignment/order.
On a "global level" I'd create a collection of type TheTile to hold the currently selected tiles. Something like: List<TheTile>.
And I'd create a master collection of the form:
List<RowOfTiles> to facilitate rapid enumeration of the whole collection and manipulation of it. Or maybe just a "flat list" of type List<TheTile> to hold all the Tiles.
It took me less than ten minutes to implement a simple working prototype of this grid of "nested" UserControls in WinForms, all properly labeled from #1~80, and which switched tile colors (switched the background color of the Label enclosed in the TheTile UserControl) as clikcing (the Label)toggled TheTile between 'Selected and 'Unselected states, and updated the master (global static, on the Main Form) collection of "SelectedTiles."
Screen shot here:[^]
While I could not find any clear description of "Cleopatra Keno" on the web, I was baffled enough reading the WikiP entry on Keno itself
What really puzzles me in your description of Cleopatra flavor Keno is the implication that the user can do something while the game is in progress, if I interpret what you say in the words: "Hit during game play" correctly, but, please, don't feel you need to educate me on this, because I guarantee you I'll never play Keno : I gamble with my life everyday riding a bicycle in the northern Thailand anarchy known as "traffic," actually a major form of birth control, as well as a major factor in culling out the wick and sick from the population
Thanks for the impetus to actually write some code for the first time in three months !
best, Bill
p.s. pm me if you want the source for the C# WinForms quick prototype.
"Humans are amphibians ... half spirit and half animal ... as spirits they belong to the eternal world, but as animals they inhabit time. This means that while their spirit can be directed to an eternal object, their bodies, passions, and imaginations are in continual change, for to be in time, means to change. Their nearest approach to constancy, therefore, is undulation: the repeated return to a level from which they repeatedly fall back, a series of troughs and peaks.” C.S. Lewis
|
|
|
|
|
That looks slick, Bill. What you describe is generally what I started out doing. I used the layered approach in order to control color without having to mess with Paint functions. In the game, the tile center, which I represented as a button, has a medium blue color, while the text and outer border are light blue. When, before the start of a game, the player selects his numbers, the border and text change to yellow. During the play, each time the game selects a number, the center turns from medium blue to red. I can change the control main background color easily to control the border color, the backcolor property of the button to change the center color, and the foreground color of the button to change the text color. The button gives me an event that I can use to set the selected status of the player's choices. I planned to use this event to fill an array representing the selected numbers, and a random number generator to set the game's choices, then compare the arrays to determine the payoff, if any.
I was dismayed to learn from others that so many controls causes problems. It's a relief to hear from you that this isn't necessarily true. On the other hand, this caused me to look into WPF, and though I have no interest in learning XAML, the graceful way in which this framework handles events is very attractive!
Keno, by the way, is a game of pure chance. You pick numbers and hope that the machine will pick the same ones. It's logically identical with any state lottery, except that in Cleopatra Keno, the payout is 90.1% of the amount paid in; no state lottery comes close. It's fun if a particular game likes the same number you do on the night you're playing it, boring as watching paint dry if it doesn't. I much prefer Poker, since there is a chance to change the outcome by discarding some cards and drawing replacements, but as in any casino game, it is as likely to stick a hose in your pocket and suck until all it gets is lint, as it is to pay off big wins. I had a dreadful night playing Keno last Friday - nothing hit for me. But when I changed to Poker, I was $2000 ahead in a couple of hours, playing $1.25 a hand. Of course, when I went back to Poker the next day (there's not much else to do when you're staying in a hotel/casino) the Poker machines slowly took back all they'd granted me the night before, and the Keno games still hated me. Over the entire weekend, I broke even, paying for the room and meals with winnings. A free vacation is not to be scorned...
Maybe I'll pursue both approaches, just to see which turns out to be simpler. In fact, if I can find the time, a side-by-side comparison of developing the same program in WinForms and WPF might make an interesting article.
Will Rogers never met me.
|
|
|
|
|
Hi Roger,
I think I'll play with this a bit more starting with:
1. add a field at the top of the UI to show the number of Tiles selected by the player. Perhaps the user should be allowed/required to enter the number prior to play ?
2. add a "play" button (initially disabled) to trigger the game
3. "enforce" minimal selection, or prevent too many tiles being selected than the game permits: before the Play button is enabled.
4. After the "run of the game:" those tiles selected by the random number generator will have the BackColor of TheTile set to Red: that will mean the tiles selected, by the player, before the game that are "winners," will have the orange background (indicating selected) for their internal TextBox surrounded by TheTile BackColor set to Red.
5. I might implement a global enumeration for each instance of TheTile; something like:
0 unselected and not a winner
1 unselected and a winner
2 selected and not a winner
3 selected and a winner
However, if I maintain generic List collections of selected tiles, and, after the game run, a generic list of winner tiles: calculating matches is trivial, so: maybe a enumeration is not really necessary.
I'd have to do some research to figure out the algorithm for the "payout," and implement the "additional bonus runs" ... triggered when the last number selected by the player is a "winner" feature ... if I understand you correctly.
Is this "cycle of additional bonus runs" always going to use the same original tiles selected by the player, or does the player have the opportunity to change the selection before each "bonus run" ?
My guess would be that it would re-use the original numbers, and the "bonus runs" are done automatically ... with the pay-out calculated on after each run and added to the original pay-out ?
Maybe this exercise will help me get over my complete disgust with the apparent future of what I call "Windows 8 Bi-Polar," and its freak-show collage of XAML, WRT, Metro, and the "Classic Desktop" (not to mention what will happen if you want to program on ARM-driven hardware) ?
best, Bill
"Humans are amphibians ... half spirit and half animal ... as spirits they belong to the eternal world, but as animals they inhabit time. This means that while their spirit can be directed to an eternal object, their bodies, passions, and imaginations are in continual change, for to be in time, means to change. Their nearest approach to constancy, therefore, is undulation: the repeated return to a level from which they repeatedly fall back, a series of troughs and peaks.” C.S. Lewis
|
|
|
|
|
Hi Roger,
This is getting to be fun[^], and I thank you for that !
best, Bill
"Humans are amphibians ... half spirit and half animal ... as spirits they belong to the eternal world, but as animals they inhabit time. This means that while their spirit can be directed to an eternal object, their bodies, passions, and imaginations are in continual change, for to be in time, means to change. Their nearest approach to constancy, therefore, is undulation: the repeated return to a level from which they repeatedly fall back, a series of troughs and peaks.” C.S. Lewis
|
|
|
|
|
That's looking great, Bill!
Have you run into any performance/reliability problems yet? Sadly, I haven't had a chance to open VS in a week, things have been so ridiculously busy around here. It's a good thing that I don't make my living doing this, but it would be really nice to have the time to enjoy my hobby once in a while. Oh well, I have a 3-day weekend coming up, and maybe I'll get some time to play then.
Will Rogers never met me.
|
|
|
|
|
If you are going the WPF route, I would use a UniformGrid to layout your "tiles"; I use it anytime that I need to compose UI's with many similar controls and groupings (usually on-the-fly).
Here's a code-only example that doesn't require XAML source code:
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Media;
namespace CodeOnlyWPF {
class Program {
[STAThread]
static void Main( string[] args ) {
Window window = new Window() {
WindowStartupLocation = WindowStartupLocation.CenterScreen,
SizeToContent = SizeToContent.WidthAndHeight
};
UniformGrid ug = new UniformGrid() {
Columns = 10,
Rows = 8
};
for ( int i = 1; i <= 80; i++ ) {
Button btn = new Button() {
Content = i.ToString(),
Width = 40,
Height = 40,
Background = Brushes.GhostWhite
};
btn.Click += new RoutedEventHandler( btn_Click );
ug.Children.Add( btn );
}
window.Content = ug;
Application app = new Application();
app.Run( window );
}
static void btn_Click( object sender, RoutedEventArgs e ) {
Button btn = sender as Button;
if ( btn.Tag == null ) {
btn.Background = Brushes.Gold;
btn.Tag = true;
}
else {
btn.Background = Brushes.GhostWhite;
btn.Tag = null;
}
}
}
}
|
|
|
|
|
+5 An interesting example, and nice to see an example where it's all done without XAML !
thanks, Bill
"Humans are amphibians ... half spirit and half animal ... as spirits they belong to the eternal world, but as animals they inhabit time. This means that while their spirit can be directed to an eternal object, their bodies, passions, and imaginations are in continual change, for to be in time, means to change. Their nearest approach to constancy, therefore, is undulation: the repeated return to a level from which they repeatedly fall back, a series of troughs and peaks.” C.S. Lewis
|
|
|
|
|
|
That's very cool, Gerry!
I'd like to try implementing this both ways, but the XAML crap is more overhead than I have time to deal with right now, though I can certainly see some excellent uses for it - someday...
Thanks for the sampler!
Will Rogers never met me.
|
|
|
|
|
I'm importing and updating a parts table from a CSV file into a table using Linq To Sql:
public int ImportPartsFile(string FileName)
{
using (SparesDataContext dc = getDataContext())
{
using (TextFieldParser tfp = new TextFieldParser(FileName))
{
int lineNo = 0;
int imported = 0;
int updated = 0;
tfp.TextFieldType = Microsoft.VisualBasic.FileIO.FieldType.Delimited;
tfp.SetDelimiters(",");
string[] words;
while (!tfp.EndOfData)
{
words = tfp.ReadFields();
lineNo++;
string partNo = words[0];
string description = words[1];
string priceString = words[2];
if (partNo.Trim() == string.Empty || priceString == string.Empty)
{
continue;
}
priceString = priceString.Replace("$", "");
int price = Convert.ToInt32(Convert.ToDecimal(priceString));
var part = (from p in dc.tblHPParts
where p.PartNumber.Trim().ToLower() == partNo.Trim().ToLower()
select p).FirstOrDefault();
if (part == null)
{
tblHPPart partRow = new tblHPPart
{
PartNumber = partNo,
Description = description,
Price = price
};
dc.tblHPParts.InsertOnSubmit(partRow);
dc.SubmitChanges();
imported++;
}
else
{
part.Price = price;
dc.SubmitChanges();
updated++;
}
}
return imported;
}
}
}
At the point where I do
else
{
part.Price = price;
dc.SubmitChanges();
updated++;
}
if get
Row not found or changed
There are 3676 lines in the CSV file, and it dies on line 40
022N02177 ,XEROX PICKUP ROLLER ,$13
Anyone know what's wrong?
If it's not broken, fix it until it is
|
|
|
|
|
As observed in the data of line 40 given above in 022N02177 0 is zero instead of letter 'O' . But if that is the case and the part number is not found then the execution should go in to the if (part == null) block. But I want to share what I have noticed and please see whether the issue is because of that.
|
|
|
|
|
546461231
modified 17-May-12 15:24pm.
|
|
|
|
|
If you are writing for a real bookstore, you're going to need a database. There are several excellent free ones, and I can recommend SQL Server Express for your use. You have some basic requirements, you need to flesh them out - what attributes does the book need? Do you need to implement security for the application? Where are the categories going to come from? Do you need to hook up to a barcode scanner of some sort?
Good luck. I always enjoy this phase of the project.
|
|
|
|
|
HI! IT SHOULD GET AND SAVE FROM AN .TXT FILE
IF U GOT AN EMAIL I COULD MAYBE SEND IT TO YOU SO U CAN LOOK IF U WANT?
|
|
|
|
|
So this is for homework?
I don't give out my email address unless I know the person well. I used to have it enabled here on the site, but I ended up receiving between 10 to 20 requests for help a day. I have a company to run and a homelife to try and maintain, I don't have time to do anyone else's work for them.
If you have a problem with a particular piece of code, show us the parts of your code you are stuck on. Also, don't use all capitals in a post - it's considered bad form on the internet, and please don't use text speak as it's not very professional. I'm in the well over 30 year old group of people who really don't like text speak.
|
|
|
|
|
So a bad subject line, upper-case shouting, textspeak, gimme code, asking for an e-mail address, and modifying/removing earlier posts is your best attempt to get some help here? I don't think so. You violated about every rule of this web site (see "How to get an answer to your question").
|
|
|
|
|
You do...
You do indeed.
I wasn't, now I am, then I won't be anymore.
|
|
|
|
|
I was trying to determine on how to get this to work.
When clicking on either up or down, its already set to 0.1 increment/decrement value.
However, when shift key is pressed and clicking either up or down, the increment would change to 1.0 increment/decrement.
I've done the coding but it delayed the increment change. When I shift-click, I had to click twice on the up button for the step value to change.
What's the effective way to get the step value to change upon the shift-click is detected?
|
|
|
|
|
Create your own class, derived from NumericUpDown. Override the UpButton and DownButton methods:
public class MyUpDown : NumericUpDown
{
public override void UpButton()
{
decimal save = Increment;
if ((Control.ModifierKeys & Keys.Shift) == Keys.Shift)
{
Increment *= 10;
}
base.UpButton();
Increment = save;
}
public override void DownButton()
{
decimal save = Increment;
if ((Control.ModifierKeys & Keys.Shift) == Keys.Shift)
{
Increment *= 10;
}
base.DownButton();
Increment = save;
}
}
Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water
|
|
|
|
|
In the C# Visual Studio 2010 project I am working on, I cannot edit or add a path to a referece file. I have inherited a project at work. When I open the project and go to the references scetion in the Visual Studio 2010 IDE there are some little yellow warning signs showing that there is something amiss with the reference listed there.
But when I click on the item and look at the missing path, I find that the name "Path" is in grey suggesting that I cannot edit it and, sure enough, I cannot add the path name to the adjoining field. What causes this? I have the solution file and the project file checked out in edit mode.
When I open the project file, the error list also gives the warnings for each missing reference:
"The reference component '(the file name)' cound not be found"
Well, I know where they are but editing the path to point there is the problem.
|
|
|
|
|
Try deleting them from the project and then adding them in again using the actual location.
Programming is work, it isn't finger painting. Luc Pattyn
|
|
|
|
|
That probably would have worked.
A Project file is an XML file.
We found that the project file had a hand-coded reference that was wrong.
|
|
|
|
|
The project file had a hand-coded reference that was wrong.
|
|
|
|
|
Hi,
Can I use a user control as a base class to write some
user control variations. I have a user control with a panel. I would like to create another user control based on the first, but with some controls in that panel. How can I do this using the designer ?
tia
|
|
|
|
|
You certainly can:
class ExtendedUserControl : MyUserControl {
}
I've no idea if you can create one in the designer but you can certainly design one once it exists (a previous project of mine was full of these).
Take note though that if MyUserControl is abstract, VS's designer throws a fit and refuses to design it (not sure if this is also true in e.g. SharpDevelop). That can be very annoying.
|
|
|
|
|