|
I think the window is closed at this moment.
Can't you send a message to the process?
|
|
|
|
|
now i can get the handle by form caption (GetWindowByCaption) but it looks frozen (no repaint, the textboxes are complety missing). but it seems i am able to set the needed values.
thanks for ur help!
|
|
|
|
|
|
I have a new windows application project using C# and I make setup project.
In the windows application project I have MDIParent as Main Form and i write this code to change the language from English to Arabic:
System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("ar-EG");
System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("ar-EG");
this.Controls.Clear();
this.InitializeComponent();
this method is fine when i run the application.
but when i install the setup project this method not change any thing.
i need help about this problem.
thanks
wael salem
|
|
|
|
|
I'm having trouble implementing a depth chart for my football simulator program. The way my program is structured, I have a Player class, a Team class, and a League class--the core classes. The depthchart would group players by their position and, by each position, sort by OVR (integer) in descending order (but only if their injury status is "false"--governed by a CanPlay method in my Player class; otherwise, they are not eligible for the depthchart). Position is a PlayerPosition type and PlayerPosition is enumerated as such:
[code]
public enum PlayerPosition { QB, HB, WR, TE, LT, LG, C, RG, RT, DE, DT, OLB, MLB, CB, FS, SS }
[/code]
This is in my Team class:
[code]
public List<Player> depthChart { get; set; }
public List<Player>[] DepthChart
{
get
{
var result = new List<Player>[Enum.GetValues(typeof(PlayerPosition)).Length];
foreach (PlayerPosition pos in Enum.GetValues(typeof(PlayerPosition)))
{
result[(int)pos] = this.Players.Where(pl => pl.position == pos && pl.CanPlay).OrderByDescending(pl => pl.OVR).ToList();
}
return result;
}
[/code]
These are in my Main() method: two attempts to obtain information from the depth chart.
Method 1:
[code]
Team t = league.Teams[0];
var depthChart = t.DepthChart;
Console.WriteLine(depthChart);
[/code]
Method 2:
[code]
foreach (PlayerPosition pos in Enum.GetValues(typeof(PlayerPosition)))
{
Console.Write(pos.ToString() + ':');
depthChart[(int)pos].ForEach(p => Console.Write(' ' + p.lastName));
Console.WriteLine();
}
[/code]
For method 1, I get on the console readout: System.Collections.Generic.List`1[FranchiseSim.Player][]
For method 2, I get on the console readout only the proper position strings (like QB, RB, etc.) and the colon ( but nothing from the depth chart.
|
|
|
|
|
First, a direct answer to your questions:
Method 1
var depthChart = t.DepthChart;
Console.WriteLine(depthChart);
depthChart will be a List<Player> so the .ToString() method will just return the typename of the depthChart . To get the player roster you need to iterate over the list and get output each player individually. You should put a method in your Team class (NOT in the main method- bad encapsulation).
Method 2
foreach (PlayerPosition pos in Enum.GetValues(typeof(PlayerPosition)))
{
Console.Write(pos.ToString() + ':');
depthChart[(int)pos].ForEach(p => Console.Write(' ' + p.lastName));
Console.WriteLine();
}
Is more complicated. The position of a type of player in the depth chart doesn't correspond to the position in the depthChart list, unless you ONLY add them in the order they appear in the enum. To do so would be very bad design. If (and only if) you have one player per position, you could consider a Dictionary<PlayerPosition, Player> Though even this is messy.
Now for the hard part, I think the overall design of the above is wrong. Some people will disagree with me, others will (hopefully) agree you can wrapper all the following up in <IMO> tags if you like . There is debate about the use of enums . I fall into the camp that they are [mostly] evil. The prescence of enums normally indicates a lack of polymorphism that should be expressed. In your case I think you should have something like the following:
public Interface IPlayer
{
string Surname {get; set;}
string PositionName { get; }
}
public abstract class Player : IPlayer
{
public string Surname {get; set;}
public string PositionName { get; protected set; }
}
public class QuaterBack : Player
{
public QuaterBack()
{
PositionName = "Quater Back";
}
}
public class WideReciever : Player
{
public QuaterBack()
{
PositionName = "Wide Reciever";
}
}
public interface ITeam
{
List<IPlayer> Players {get; }
}
public class Team : ITeam
{
public List<IPlayer> Players {get; private set}
public string TeamRoster()
{
string roster = "";
Players.ForEach( p=> roster += p.PositionName + ": " + p.Surname + " ");
return roster;
}
public Team()
{
Players = new List<IPlayer>();
}
}
The big question should now be why bother? Functionality is now encapsulated in the correct place, Player handles whatever the player does,Team will handle team-level stuff. Also, you can add extra properties to Player , for example a Positional Shortcode e.g. ("QB"), in the original implementation you would have to keep a dictionary for such information (and any other information relating to the position. Additionally The above can be made to demonstrate polymorhpism: As an example, let's say only Quaterbacks are allowed to kick off (I don't know enough about American football for a real example), you can add a KickOff method to a Quaterback without implementing it for any of the other player types. Not only that, but long enums often lead to messy switch statements (or long lists of if s), giving off a rank code-smell as they go.
The code I've given isn't perfect (I haven't thought about it very deeply), but hopefully will provide a starting point. For example, I think there really should be a IPlayerType interface subclassed by PlayerType type inherted per position (e.g. QuaterBack ), and the Player should expose a property of IPlayerType , rather than BE a QuaterBack or LineBack or whatever. This will allow the player to change position easily and encapsultes the position properly, against the player.
Take a look at for some started WRT enums:
http://devpinoy.org/blogs/cruizer/archive/2007/09/12/enums-are-evil.aspx[^]
and http://www.colourcoding.net/Blog/archive/2009/07/25/enums-are-evil-the-state-pattern.aspx[^]
One of the problems in describing the reason why you shouldn't use enums is that they work when starting out writing a class (so any explanation of why not to use them seems longer/harder than the original), but as the class develops the shortfalls start to appear.
Hope this helps!
CCC solved so far: 2 (including a Hard One!)
37!?!! - Randall, Clerks
|
|
|
|
|
Thank you for your response. I've considered your ideas and it occurred to me that maybe all of this isn't necessary afterall; perhaps, for each team, I could simply list each position with each player at that position in descending order by OVR with simple loops.
This is in my Main() method
foreach (Team t in league.Teams)
{
Console.WriteLine("");
Console.WriteLine(t.Name + " " + t.Nickname);
foreach (PlayerPosition pos in Enum.GetValues(typeof(PlayerPosition)))
{
Console.WriteLine(pos);
league.AllPlayers.Where(pl => pl.position == pos).OrderByDescending(pl => pl.OVR).ToList().ForEach(pl => pl.Print());
}
}
The only problem with this code is that for each team displayed, it's putting ALL of the players in the league, regardless of what team they're on, in each team's roster that is displayed.
I believe has to do with the AllPlayers designation. This is located in my League class:
public List<Player> AllPlayers
{
get
{
var list = from t in Teams
from p in t.Players
select p;
return list.ToList();
}
}
How would you suggest I fix this?
|
|
|
|
|
This idea is not good from a from an oo point of view. It is important to encapsulate your classes properly.
You have a need for a team class, it should be responsible for maintaining it's own list of players. Likewise each player must maintain it's own information (e.g. Name, Position etc).
I suggest you try my example. To get the list of players in a particular position, you would just have to loop around each team, then loop each roster looking for players of the type required.
I also suggest you find a good OO book and learn the basic principles. If you are using an OO language like C#, learning OO principles will make coding easier for you, and the code you will produce will be neater and easier to maintain and understand. It is difficult to make the mental shift from procedure to object oriented programming, but doing so will make your life easier when using c# and is well worth the effort.
CCC solved so far: 2 (including a Hard One!)
37!?!! - Randall, Clerks
|
|
|
|
|
I have a winform with two texboxes, one below the other.
When i resize horizontal there is no problem, but when i want to resize vertical only can resize one and i need to resize both proportionally.
Already tryed many anchor property configurations without luck...
Any idea?
Thanks in advance.
|
|
|
|
|
Hi,
I was thinking about Anchor property as well. How about using a SplitContainer in a horizontal oritation, with two textBoxes Dock property set as Fill?
Br!"
Sun
|
|
|
|
|
You suggestion not soove my needs... each texbox is on different groupbox...
|
|
|
|
|
I solved it with main form Resize event... and playing with groupbox Top and Height properties.
Thanks anyways....
|
|
|
|
|
Hi,I am doing a project related to image erosion .. can someone help me to write codings for th erosion process alone in c# (windows application).
|
|
|
|
|
hi,this is suhdir final year in computer science and engineering.i am doing a project for my final year.project is a chatting software.project details:
software is similar to gtalk and diffrence is here conference call is possible.i have done the chatting part but one thing i am in delema how to make call??plz give me some idea how to make call.time is short in my hand.plz help me.
|
|
|
|
|
Are you talking about this :
http://dotnet.org.za/ruari/archive/2004/11/10/6254.aspx
In fact, I havent tried it. I did a chat application but not actually making conference calls.
Might be some1 else can help.
|
|
|
|
|
Hi,
Does anyone have idea on how to create a few radio buttons using data from XML file?
I would like to have the buttons to be created once I load the form. But I do not have any idea as I started learn about XML today.
Thank you in advance.
Zar Ni
|
|
|
|
|
Well.. just parse the XML document (plenty of tutorials online) and find the elements representing the radio buttons. And in your Form_Load event you create the buttons and add them to the Form. Good luck!
|
|
|
|
|
Can't work out what I'm doing wrong. When I programmatically add a button to the first cell of a table layout panel by calling 'tlp.Controls.Add(newButton, 0, 0) ' it works the first three times, shifting existing controls along a cell as expected. However after the third time the same code inserts the button into the second cell a few times, then after more calls, the third etc. Examlpe code below.
Is there a limit on how many times you can call Controls.Add(ctrl, column, row) for a given cell?
private int nextIndex = 1;
private void bAddButton_Click(object sender, EventArgs e)
{
Button newButton = new Button();
newButton.Text = nextIndex.ToString();
tableLayoutPanel1.Controls.Add(newButton, 0, 0);
nextIndex++;
}
|
|
|
|
|
Message Closed
modified 23-Nov-14 7:05am.
|
|
|
|
|
Thank you for your quick reply. However I only want one button per cell for scaling reasons.
|
|
|
|
|
Hello
I am working on examination project. I hava a column Position in Database. I am storing position in this column on the basis of obtained marks.suppose that i have entered 50 students record and assign each student a position on the basis of obtained marks. now i enter 51 number student and the obtained marks of this new student are higher than all students,definitely i will assign 1(ist position) to this student and all other students Positions will be changed. A student who is on ist position before entering 51 student record will changed from ist to 2nd position and rest of students positions also changed.
Now when i use update command from C# it only updates one row and left other rows to old values. i am using update in a loop.
And only a single row which is updated is of those student who has less marks than new 51 number student and rest of the rows are not updated.
Plz reply immediate
Thanks
Regards Usman Ahmad
|
|
|
|
|
Member 2367800 wrote: Plz reply immediate
Nobody is going to reply if you post a question with this.
How about posting the update code and we can see where the problem is. For starters I would re-evaluate the whole order. Just updating/adding the one student would not "auto" update the rest of them. Post the code you use for the update and we can check or advise from there.
Excellence is doing ordinary things extraordinarily well.
|
|
|
|
|
Thanks to every one who replied me. I have solve the problem.
regards
Usman Ahmad
|
|
|
|
|
Is there any way to convert HTML content to plain text.
I want simple/plain text present in HTML content.
|
|
|
|
|
Message Closed
modified 23-Nov-14 7:06am.
|
|
|
|