|
private object castTo(string typeName, object value)
{
Type castingType = Type.GetType(typeName);
return Convert.ChangeType(value, castingType);
}
That doesn't use generics, and it isn't type safe, but it does have the same method signature and have almost identical behaviour (I think you'll need to fully specify the type name though)
For a generic version, try this:
private T castTo<T>(object value)
{
Type castingType = typeof(T);
return (T)Convert.ChangeType(value, castingType);
}
It's type safe and far better-looking. One niggle though - the converted type must implement IConvertible
|
|
|
|
|
How to find Internet Explorer target folder, i.e., the IE installation folder in a System through c# code?
I want inject a dll in IE installation folder, In c# How can I do this through a MSI setup?
|
|
|
|
|
well Internet Explorer puts itself in the program files, and as far as I know it is always in 'Internet Explorer' so maybe the following will work for you...
string IEFolderPath = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles) + "\\Internet Explorer\\";
Of Course, I don't know this for sure, I suppose you could look in the system registry settings and see if the installation folder is stored in there somewhere
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|
|
my 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;
namespace Din_Checkers
{
class Board
{
public const int x_bounds = 8;
public const int y_bounds = 8;
public PictureBox[,] checkers_board { get; set; }
public Label score = new Label();
public ImageList imageList1 = new ImageList();
public int goldEaten = 0;
public int silverEaten = 0;
public int x = 0;
public int y = 0;
public void Board()
{
checkers_board = new PictureBox[x_bounds, y_bounds];
imageList1.Images.Add(Image.FromFile("Images\\silver.jpg"));
imageList1.Images.Add(Image.FromFile("Images\\gold.jpg"));
Image loadGold = imageList1.Images[0];
Image loadSilver = imageList1.Images[1];
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;
}
}
else if (i > 4)
{
if (((i + j) % 2 == 0) || (i % 2 == 1 && j % 2 == 1))
{
checkers_board[i, j].BackgroundImage = loadSilver;
}
}
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;
}
}
score.Top = 510;
score.Left = 250;
score.Width = 500;
for (int i = 0; i < checkers_board.GetLength(0); i++)
{
for (int j = 0; j < checkers_board.GetLength(1); j++)
{
checkers_board[i, j].Click += new EventHandler(ChooseEvent_Click);
}
}
}
public void DrawScore()
{
score.Text = "תוצאה: זהובים אכולים- " + goldEaten.ToString() + " כסופים אכולים- " + silverEaten.ToString();
}
public void ChooseEvent_Click(object sender, EventArgs e)
{
string eventChoose = "";
for (int i = 0; i < checkers_board.GetLength(0); i++)
{
for (int j = 0; j < checkers_board.GetLength(1); j++)
{
if (eventChoose == "")
{
if (checkers_board[i, j].BackColor == Color.White)
{
eventChoose = "Handle_Board";
}
}
if (checkers_board[i, j].BackColor == Color.Green)
{
eventChoose = "move";
}
}
}
if (eventChoose == "move")
{
MoveChecker_Click(sender, e);
}
else
{
HandleBoard_Click(sender, e);
}
}
public void HandleBoard_Click(object sender, EventArgs e)
{
for (int i = 0; i < checkers_board.GetLength(0); i++)
{
for (int j = 0; j < checkers_board.GetLength(1); j++)
{
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;
}
}
}
for (int i = 0; i < checkers_board.GetLength(0); i++)
{
for (int j = 0; j < checkers_board.GetLength(1); j++)
{
if (checkers_board[i, j] == ((PictureBox)sender))
{
x = i;
y = j;
}
}
}
score.Text = x.ToString() + " " + y.ToString() + "fun0";
int start_x = x - 1, start_y = y - 1, end_x = x + 1, end_y = y + 1;
if (start_x < 0)
{
start_x = 0;
}
if (start_y < 0)
{
start_y = 0;
}
if (end_x > checkers_board.GetLength(0) - 1)
{
end_x = checkers_board.GetLength(0) - 1;
}
if (end_y > checkers_board.GetLength(1) - 1)
{
end_y = checkers_board.GetLength(1) - 1;
}
for (int i = start_x; i <= end_x; i++)
{
for (int j = start_y; j <= end_y; j++)
{
}
}
}
public void MoveChecker_Click(object sender, EventArgs e)
{
for (int i = 0; i < checkers_board.GetLength(0); i++)
{
for (int j = 0; j < checkers_board.GetLength(1); j++)
{
if (checkers_board[i, j] == ((PictureBox)sender))
{
x = i;
y = j;
}
}
}
score.Text = x.ToString() + " " + y.ToString() + "func";
checkers_board[x, y].BackColor = Color.White;
checkers_board[x + 1, y - 1].BackColor = Color.White;
checkers_board[x - 1, y - 1].BackgroundImage = null;
checkers_board[x, y].BackgroundImage = Image.FromFile("Images\\silver.jpg");
for (int i = 0; i < checkers_board.GetLength(0); i++)
{
for (int j = 0; j < checkers_board.GetLength(1); j++)
{
if (checkers_board[i, j].BackColor == Color.Green)
{
checkers_board[i, j].BackColor = Color.White;
}
}
}
}
public static void EatChecker()
{
}
}
}
it says the message in the title and it marks the constactur name what should i do?
|
|
|
|
|
constructors don't have a return type. Get rid of the 'void'
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|
|
I want to automate my mobile (Samsung SGH-X660)connected to my PC by a data cable. I want to get the sms to my PC that my mobile receive. How it is possible?
|
|
|
|
|
|
Thank you vary much for your help.
I am trying to read sms from the mobile. The content is in hex format (It may be in PDU fromat) How can I get original message.
I have used following AT commands
1: "AT"
2: "AT+CMGF=0" // 1 for text mode but it doesn't work
3: "AT+CSCS=\"8859-1\"
4: "AT+CPMS=\"SM\""
5: "AT+CMGL=4"
|
|
|
|
|
Try doing some research, this came up on Google [^] but it was mixed in with a load of junk.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
i have a Menu bar . and i want to create sub item and add it into Menu ... please give me some guide line..
|
|
|
|
|
Assuming the name of your menu is MenuStrip1, then create a new ToolStripMenuItem and add it to the DropDownItems collection of MenuStrip1
|
|
|
|
|
|
xingselex wrote: may u give me as code?
He practically did just give you it as code. If you cant work out the code from what he said then you are way out of your league with what you are trying to do. You need to get a book on the basics of .Net, possible even programming in general if all you do is copy and paste code.
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|
|
MenuItem m = new MenuItem("aaa", "1");
Menu1.Items.Add(m);
m.ChildItems.Add(new MenuItem("bbb", "2"));
m.ChildItems.Add(new MenuItem("ccc", "3"));
Padmanabhan
|
|
|
|
|
Hi,
could anyone help me how to send sms using windows application c#
how to make that
Thanks & Regards
Nath
|
|
|
|
|
Some firms run web services which you interface with and use to send the text
You can usually plug a phone into the serial port and manually send the data using it's antenna
You could send an email to the phone and hope that it gets delivered as a text message
|
|
|
|
|
i have to send sms using windows application. If there is anything please
let me know
|
|
|
|
|
I already have. Those are the three main approaches to sending an SMS. Windows application, WPF or console application - they will (almost) all use one of those three approaches. You simply have to investigate which of those would be most practical to you, and research it
|
|
|
|
|
hai
please visit www.rinoshsasidharan.wordpress.com
to see the solution
regards
Rinosh.K.Sasidharan
|
|
|
|
|
Hi,
i am trying to get cursor position clicking anywhere except my application. I used keydown event on my form for checking, it works. But when i click anywhere it does'nt work
please check my code and tell me where am I doing mistak?
Thank you in Advance
(Riaz)
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 MM1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
Click += new System.EventHandler(Raised_Click);
}
private void Raised_Click(object sender, EventArgs e)
{
label1.Text = Cursor.Position.X.ToString() + " ; " + Cursor.Position.Y.ToString();
}
private void Form1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Space)
{
label1.Text = Cursor.Position.X.ToString() + " ; " + Cursor.Position.Y.ToString();
}
}
}
}
modified on Friday, May 22, 2009 2:27 AM
|
|
|
|
|
M Riaz Bashir wrote: But when i click anywhere it does'nt work
Can you explain this a bit more? I tested the code and where ever I clicked on the form the label displays the XY co-ordinates fine.
Excellence is doing ordinary things extraordinarily well.
|
|
|
|
|
except the running form, I need cursore position when I click anywhere on the desktop
|
|
|
|
|
You need to get the Mouse click location even if user DOES NOT clicks on the UI of your application. Is it? Then you need to use Global Mouse and keyboard hook.
This[^] article will help you.
जय हिंद
|
|
|
|
|
Thank you
|
|
|
|
|
I need to add excel 2007 piviot table functinality to my windows application For Business Intelligence Application. Data is take from the Cube. I already got office 2003 piviot table functinality. But I need office 2007 piviot table functinality to this application. Please help me how to this.
Dushan Perera
|
|
|
|