|
Use Int32.TryParse[^] and if both return true, check the fields that the out parameter assigns to against your logic.
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)
|
|
|
|
|
Didn't get it correctly..
I am very new to coding.. on which event do i have to check . can i get a sample code for the same
|
|
|
|
|
It depends on how you want to handle it.
The code below uses the Validating[^] event, but that may not be appropriate for your situation. I prefer to stop invalid characters getting into the textbox in the first place. Check out my article - Simple Numeric TextBox[^].
Assumes textBox1, textBox2 and label1 already exist on the form.
private static readonly int MinValue = 0;
private static readonly int MaxValue = 100;
int textBox1Value;
int textBox2Value;
bool textBox1Valid;
bool textBox2Valid;
private void textBox1_Validating(object sender, CancelEventArgs e)
{
if (!ValidateTextBoxes() && !textBox1Valid)
{
e.Cancel = true;
textBox1.SelectAll();
}
}
private void textBox2_Validating(object sender, CancelEventArgs e)
{
if (!ValidateTextBoxes() && !textBox2Valid)
{
e.Cancel = true;
textBox2.SelectAll();
}
}
private bool ValidateTextBoxes()
{
textBox1Valid = int.TryParse(textBox1.Text, out textBox1Value);
textBox2Valid = int.TryParse(textBox2.Text, out textBox2Value);
if (textBox1Valid)
textBox1Valid = textBox1Value >= MinValue && textBox1Value <= MaxValue;
if (textBox2Valid)
textBox2Valid = textBox2Value >= MinValue && textBox2Value <= MaxValue;
SetResultLabel(textBox1Valid && textBox2Valid);
return textBox1Valid && textBox2Valid;
}
private void SetResultLabel(bool validated)
{
if (validated)
label1.Text = string.Format("{0}:{1}", textBox1Value, textBox2Value);
else
label1.Text = string.Empty;
}
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)
|
|
|
|
|
Hi
My application (Gaming AntiCheat Application) takes screenshots and uploads it to a server. But the image size is too big. I want to lower the image size by reducing the quality of the picture. But I don't know how to do it. I have searched CodeProject and Google but I couldn't see a satisfacting answer.
If you need the screenshot code that I am using, here it is:
int screenWidth = Screen.GetBounds(new Point(0, 0)).Width;
int screenHeight = Screen.GetBounds(new Point(0, 0)).Height;
Rectangle bounds = Screen.GetBounds(Point.Empty);
using (Bitmap bitmap = new Bitmap(bounds.Width, bounds.Height))
{
using (Graphics g = Graphics.FromImage(bitmap))
{
g.CopyFromScreen(Point.Empty, Point.Empty, bounds.Size);
}
Graphics graphicImage = Graphics.FromImage(bitmap);
graphicImage.SmoothingMode = SmoothingMode.AntiAlias;
Rectangle r = new Rectangle(150, 10, 130, 35);
graphicImage.DrawRectangle(new Pen(Color.White, 100), r);
string datetime = DateTime.Now.ToString().Replace(':', '.');
string datetime2 = datetime.Replace(' ', '.');
string cozunurluk= screenWidth + " x " + screenHeight;
graphicImage.DrawString(depo.username, new Font("Arial", 12, FontStyle.Bold), SystemBrushes.WindowText, new Point(110, 10));
graphicImage.DrawString(DateTime.Now.ToString(), new Font("Arial", 12, FontStyle.Bold), SystemBrushes.WindowText, new Point(110, 35));
graphicImage.DrawString(cozunurluk, new Font("Arial", 12, FontStyle.Bold), SystemBrushes.WindowText, new Point(110, 60));
Bitmap baskilogo = kaynaklar.baskilogo;
graphicImage.DrawImage(baskilogo, 321, 0, 236, 96);
string localresimadi = (depo.userid + "." + datetime2 + ".hl2" + ".bac");
bitmap.Save(localresimadi, ImageFormat.Jpeg);
depo.resimlist = depo.resimlist + ";" + localresimadi;
depo.ekrangoruntusuadedi++;
txtSSnr.Text = depo.ekrangoruntusuadedi.ToString();
graphicImage.Dispose();
bitmap.Dispose();
try
{
StreamReader oku = new StreamReader("upl.bac");
depo.uplbacsatir = rot13.use( oku.ReadLine() );
oku.Close();
oku.Dispose();
}
catch (FileNotFoundException)
{
depo.uplbacsatir = null;
}
StreamWriter yaz = new StreamWriter("upl.bac");
yaz.Write( rot13.use(depo.uplbacsatir) + rot13.use(localresimadi + ";"));
yaz.Close();
yaz.Dispose();
}
Thanks.
|
|
|
|
|
|
"You obviously didn't search hard enough, here's what I came up with using Google for two minutes:
http://msdn.microsoft.com/en-US/library/system.drawing.imaging.encoderparameter.aspx[^]"
I have seen that, but I didn't understand what to do exactly.
|
|
|
|
|
Theoretically, if you knew information about what was supposed to be on the screen at specific times you could probably pass time, location, and image hash instead of the entire image to identify cheating.
Need software developed? Offering C# development all over the United States, ERL GLOBAL, Inc is the only call you will have to make.
If you don't ask questions the answers won't stand in your way.
Most of this sig is for Google, not ego.
|
|
|
|
|
I couldn't exactly understand what you are trying to mean. Are you trying to say that I am making a keylogger-like application. This is just a anti-cheating application like X-ray Anti-Cheat. You can access the pictures it takes from http://www.xraygaming.com/
Or maybe I understood your message wrong
|
|
|
|
|
I am trying to see if you are screen capturing your application and sending it to a server to check for cheating you could hash a particular part of the screen to check for cheating instead of uploading the entire screen.
Besides, uploading an entire screen shot is unethical and so is key logging.
Need software developed? Offering C# development all over the United States, ERL GLOBAL, Inc is the only call you will have to make.
If you don't ask questions the answers won't stand in your way.
Most of this sig is for Google, not ego.
|
|
|
|
|
My application only captures the screen when the game is open. Uploading the entire screen is unethical only when the user doesn't know what the application is doing.
You can see cheater's screenshots here:
http://www.xraygaming.com/index.php?pageid=gallery[^]
So I can't check for cheating by hashing a particular part of the screen. Because it always changes.
|
|
|
|
|
Yeah its pretty naive anti-cheat used in private enthusiast gaming ladders. The condition of playing in their ranked matches is that you run the client, which randomly uploads screenshots of your game so you can prove you don't have transparant walls or other cheats.
They always end up failing, as they are trivial to work around... eg Novacap, Octinium, CEVO's client...
The done thing seems to be re-implementing them in the same way, and look surprised when they get defeated
|
|
|
|
|
Hi,
I have a problem with my CTRL+C Keylogger.
It's an application which listens (hook) for CTRL+C and if it is triggered, it searches for the clipboard text (if it is text).
It works perfectly, but it is one step behind.
eg. if I have a text: abc def geh
and I first copy abc, nothing happends. If I then copy def, it has abc in the clipboard.
So, then I made this thread on tek-tips and a person there gave me a suggestion that maybe my application triggers too fast (eg. tries to use the clipboard, befire it's filled).
I then tried a thread.sleep(1000)..
This worked (on vista), but not on xp sp3.
Here is the code
if (nCode >= 0 && wParam == (IntPtr)WM_KEYDOWN)
{
int vkCode = Marshal.ReadInt32(lParam);
if (Keys.C == (Keys)vkCode && Keys.Control == Control.ModifierKeys)
{
Thread.Sleep(1000);
if (iData.GetDataPresent(DataFormats.Text, true))
{
frm2.setSearch(iData.GetData(DataFormats.Text, true).ToString());
}
}
}
Olav Alexander Mjelde
|
|
|
|
|
Olav Alexander Mjelde wrote:
So, then I made this thread on tek-tips and a person there gave me a suggestion that maybe my application triggers too fast (eg. tries to use the clipboard, befire it's filled).
That's correct
Olav Alexander Mjelde wrote:
I then tried a thread.sleep(1000)..
That's a very unreliable way.
Here's the proper way, register yourself as a clipboard viewer and get notified of changes in the clipboard:
http://www.radsoftware.com.au/articles/clipboardmonitor.aspx[^]
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Hi. I googled this but havent found anything usefull. Now, i turn to you. The CP community.
I'd like to convert some JPEG files to TIF and compress them with CCITT Fax 4.
For an example take IrFan View. You open a file in Irfan and then click "Save as...". Irfan has a plugin for this (i guess) in its app. folder\plugins... but dont know which one. Even if i'd know, i dont know how to use .dll files.
So, does anyone know how to convert, i mean, compress a file into CCITT Fax 4 (b&w)?
Thanks in advance!
Regards,
Matjaž
|
|
|
|
|
http://www.vbdotnetforums.com/graphics-gdi/19552-group-4-compression-tif.html
|
|
|
|
|
Wow. Thank you Mark! This was really helpful.
Thanks again!!
Regards,
Matjaž
|
|
|
|
|
Ah np, i remember seeing the option when I was messing around with TIFFs for some other reason.
|
|
|
|
|
Hi,
Is it possible to take backup of Device Drivers programatically ?
Regards......
|
|
|
|
|
Hi
I would like to read the content of XML in c#
I’ve main XML that contain several include to additional xml
I’m trying to read nodes from main XML but I always got zero,
In case I’m copy the sub XML content to main XML it work
I know I can do include in XML another XML and it should be the same as writing the text in the same XML
What could be the problem?
See code below
Main XML
<tests>
<num_of_tests>4</num_of_tests>
<include href="test_rx25ghz.xml" />
<include href="test_rx35ghz.xml" />
<include href="test_tx25ghz.xml" />
<include href="test_tx35ghz.xml" />
</tests>
SUB XML
<test>
<testname>RX</testname>
<description>RX test on 2.5Ghz</description>
<frequency>250475000</frequency>
</test>
C# code
private XmlDocument m_xDoc;
private XmlElement m_Root;
m_xDoc = new XmlDocument();
m_xDoc.Load(m_mainXMLTest);
m_Root = m_xDoc.DocumentElement;
m_nodeItems = m_Root.GetElementsByTagName("test");
the problem is
m_nodeItems.count = 0
Please advice
Ronen
|
|
|
|
|
If the performance is critical, what should I choose:
1. A comfortable and flexible solution: an array TSymbol[] , where Symbol is a struct {int a, int b} and access it via arr[n].a, arr[n].b
OR
2. Redesign everything and give up a generic class of type <TSymbol> : an array int[][] , and access it via arr[n][0], arr[n][1]
In fact I ask about a C# difference between
int[] arr = new int[2];
arr[0], arr[1] and
Symbol[] s = new Symbol;
s.a, s.b
Greetings - Gajatko
Portable.NET is part of DotGNU, a project to build a complete Free Software replacement for .NET - a system that truly belongs to the developers.
|
|
|
|
|
Hi,
since both (int and structs) are value types, they are stored at the stack. So accessing an int or an struct is an access to the fast stack. So I would say it doesn't matter, but I really don't know it exactly.
Regards
Sebastian
|
|
|
|
|
SeMartens wrote: since both (int and structs) are value types, they are stored at the stack.
An array of some (value) types results in a reference type, though.
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
So, let me guess writing [][] (Jagged array) refers to two "different" seperate arrays. Then using the struct would be faster because you are only one array reference instead of two?
Am I totally wrong?
|
|
|
|
|
SeMartens wrote: So, let me guess writing [][] (Jagged array) refers to two "different" seperate arrays.
Actually, a jagged array [n][m] will create n*m arrays.
SeMartens wrote: Then using the struct would be faster because you are only one array reference instead of two?
MSDN[^] writes a bit about performance of value and reference types. If value types have a lot of members, that it might be better to use a reference to this type using the ref keyword. Of course this is only applicable if you want to allow modification of the value type. Reference types have some GC overhead though.
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Not 100% cetain, but with modern processors and compilers there should be negligible odds. Any given structure is of constant size, and the offset into the structure for any given member is also constant. The array indexing is therefore trivial, and the member offsetting calculable at compile-time. e.g. If iterating in a for loop, it might typically add the struct size onto the index each time, which was originally primed with the address of the member variable in the initial array element.
|
|
|
|
|