|
The simplest but wrongest way would be to make the TextBox public.
A better way is to make a public property that allows the other form to get and/or set the Text property of the TextBox.
There are other ways that may be more appropriate to your situation, but we would need to know more about what you are trying to do.
However you do it, you may have to protect against cross-thread access problems.
|
|
|
|
|
I want to get the properties value of that object and change it to
a new value as I want.
|
|
|
|
|
You would have to change the access modifier for the textbox.
Why is common sense not common?
Never argue with an idiot. They will drag you down to their level where they are an expert.
Sometimes it takes a lot of work to be lazy
Individuality is fine, as long as we do it together - F. Burns
|
|
|
|
|
by changing the modifier I only can get the properties of
that object (the values can be read) how can we set the
properties to a new value?
|
|
|
|
|
Pass value between forms using events[^] explains the correct way to do such things.
What you had, creating yet another Form1, is not going to work, as you are looking at one instance of Form1 and programmatically changing another unrelated instance.
Making Controls public would work but is hardly acceptable, as now "the whole world" could modify, move, resize, etc. said Control.
|
|
|
|
|
|
I hope this will help:
Form1 frm=new Form1();
frm.Show();
TextBox textBox=frm.Controls.Find("textBox1",false)[0] as TextBox;
textBox.Text = "new text";
|
|
|
|
|
I'm working on a custom Attribute. What I'd like is to have it take a parameter (e.g. [MyAttribute(foo)] ), but the type I want to use isn't allowed (non-constant).
So, I made my Attribute abstract and derived other Attributes to specify the desired values:
class FooAttribute : MyAttribute
{
public FooAttribute() : base ( foo ) {}
}
class BarAttribute : MyAttribute
{
public BarAttribute() : base ( bar ) {}
}
This works as expected except that instances of both derived Attributes can then be applied and they don't get flagged as duplicates (of MyAttribute); from a certain point of view, AllowMultiple=false should disallow multiple instances of the base class. In practice this doesn't happen, and that's understandable, but I want to find a way to get it to work that way.
I investigated the TypeId property thinking that would work, but it doesn't seem to.
Has anyone here happened upon this situation and found a solution?
Currently my code is just using the first instance of MyAttribute it finds, but I'm considering having the code throw an Exception if it finds multiples -- does anyone here have an opinion on which course of action is better?
|
|
|
|
|
I am making a program in which I established connection with sql server using DSN. I am using ODBCConnection class. I want to check that, DSN which is created is for access or sql server. I did google but not getting helpful information. I am using c# and visual studio 2008.
Thanks.
|
|
|
|
|
Unless you are developing your program to work with both -- as in using Access for testing, but SQL Server for production, then I don't really see a need to do this.
If you are doing that, then I might suggest that you create a table with that information and query it.
If, on the other hand, you are given a Connection and want to determine which it is, then the best I can say is to use the GetSchema method and examine the resultant table for clues.
|
|
|
|
|
I need to validate dsn name that it is valid or not. Like we can choose any dsn name which is for access, excel, or sql server.
|
|
|
|
|
If you want to check whether or not a given DSN points to your database, then I suggest making a Connection, calling GetSchema, and looking for your tables.
|
|
|
|
|
Hi All,
I have a printed document with lots of check-boxes, I must automatically detect which check-boxes are marked, and save these into a database. (Using C#)
Can anybody give me some hints where to start digging or examples of how I should start on this task.
Thanks alot.
|
|
|
|
|
Certainly willing to try
If the images will be obtained from a scanner, I'd suggest that you first implement code that will detect the skew angle and correct it. I seem to remember adapting some code with a name of gmeDeskew or something like that.
Next, you'll want to define the areas of interest. That is, the areas that will contain check-boxes that should be examined. Since different skew angles will result in images of slightly different sizes when deskewed, I'd suggest that these areas are defined using percentage of document width/height, as opposed to being defined in terms of number of pixels.
Once you have correctly deskewed the image and identified the areas of interest, you'll want to scan the image line-by-line, row by row to determine areas likely to contain check-boxes within your area of interest. Once done, examine the heck-boxes by simply counting the number of percentage of pixels that are below a certain brightness (you'll have to determine this threshold)
I coded an app once that would take scanned images of (college) attendance sheets, identifying the class name/week from a barcode, the student IDs from barcodes, then finally - the student attendance from manually colored 'radio buttons'
With this method, I was able to take an example image (at 1/4 scale as it happened) then deskew it and draw rectangles around each of the 18 barcodes for student ID, the 18 attendance scores for the students, the class name barcode and the class date barcode.
Then when I used full size images all of my areas of interest remained aligned correctly. (Using percentages of image size GREATLY improved the accuracy of the placement of the areas of interest onto each successive image. Prior to that idea, it was very difficult to be sure that I was going to examine the pixels that made up the parts of the image I was interested in)
Something else to consider is "pattern matching", or put simply - the comparing of pre-existing images with portions of the scanned document. You could simply use two images - one of an empty square and another of a check-box with a cross/dot/dash inside it. This should be effective because regardless of the style of marking, an empty box is always going to more closely resemble the saved image you have of an empty box (rather than the checked-box).
It's an interesting topic, OMR. (optical mark recognition) Enjoy!
|
|
|
|
|
The image is scanned from the scanner, and i want to get the marked check-boxes.
Please provide me a sample code if you can .
Thanks
|
|
|
|
|
Here you go - here's the VB code to calculate the skew angle of an image.
I'd throw you the C# version, but I don't have one - I converted this code to c++
You can then find an algorithm to rotate by -skewAngle. (I'll leave that to you)
I might add, I spent many 10s of hours on this project. For your own sanity, I suggest patience!
Imports Microsoft.VisualBasic
Public Class deskew
Public Class HougLine
Public Count As Integer
Public Index As Integer
Public Alpha As Double
Public d As Double
End Class
Dim cBmp As Bitmap
Const stepsPerDeg = 5
Const minAngle = -13
Const maxAngle = 13
Dim cAlphaStart As Double = minAngle
Dim cAlphaStep As Double = 1 / stepsPerDeg
Dim cSteps As Integer = (maxAngle - minAngle) * stepsPerDeg
Dim cSinA() As Double
Dim cCosA() As Double
Dim cDMin As Double
Dim cDStep As Double = 1
Dim cDCount As Integer
Dim cHMatrix() As Integer
Public getPixelCalls As Long
Public Sub setAngleRange(ByVal minAngle As Long, ByVal maxAngle As Long)
cAlphaStart = minAngle
cSteps = (maxAngle - minAngle) / cAlphaStep
End Sub
Public Function GetSkewAngle() As Double
Dim hl() As deskew.HougLine
Dim i As Integer
Dim sum As Double
Dim count As Integer
Calc()
hl = GetTop(20)
For i = 0 To 19
sum += hl(i).Alpha
count += 1
Next
Return sum / count
End Function
Private Function GetTop(ByVal Count As Integer) As HougLine()
Dim hl() As HougLine
Dim i As Integer
Dim j As Integer
Dim tmp As HougLine
Dim AlphaIndex As Integer
Dim dIndex As Integer
ReDim hl(Count)
For i = 0 To Count - 1
hl(i) = New HougLine
Next
For i = 0 To cHMatrix.Length - 1
If cHMatrix(i) > hl(Count - 1).Count Then
hl(Count - 1).Count = cHMatrix(i)
hl(Count - 1).Index = i
j = Count - 1
While j > 0 AndAlso hl(j).Count > hl(j - 1).Count
tmp = hl(j)
hl(j) = hl(j - 1)
hl(j - 1) = tmp
j -= 1
End While
End If
Next
For i = 0 To Count - 1
dIndex = hl(i).Index \ cSteps
AlphaIndex = hl(i).Index - dIndex * cSteps
hl(i).Alpha = GetAlpha(AlphaIndex)
hl(i).d = dIndex + cDMin
Next
Return hl
End Function
Public Sub New(ByVal bmp As Bitmap)
cBmp = bmp
End Sub
Private Sub Calc()
Dim x As Integer
Dim y As Integer
Dim hMin As Integer = cBmp.Height / 4
Dim hMax As Integer = cBmp.Height * 3 / 4
Init()
For y = hMin To hMax
For x = 1 To cBmp.Width - 2
If IsBlack(x, y) Then
If Not IsBlack(x, y + 1) Then
Calc(x, y)
End If
End If
Next
Next
End Sub
Private Sub Calc(ByVal x As Integer, ByVal y As Integer)
Dim alpha As Integer
Dim d As Double
Dim dIndex As Integer
Dim Index As Integer
For alpha = 0 To cSteps - 1
d = y * cCosA(alpha) - x * cSinA(alpha)
dIndex = CalcDIndex(d)
Index = dIndex * cSteps + alpha
Try
cHMatrix(Index) += 1
Catch ex As Exception
Debug.WriteLine(ex.ToString)
End Try
Next
End Sub
Private Function CalcDIndex(ByVal d As Double) As Double
Return Convert.ToInt32(d - cDMin)
End Function
Private Function IsBlack(ByVal x As Integer, ByVal y As Integer) As Boolean
Dim c As Color
Dim luminance As Double
getPixelCalls += 1
c = cBmp.GetPixel(x, y)
luminance = (c.R * 0.299) + (c.G * 0.587) + (c.B * 0.114)
Return luminance < 140
End Function
Private Sub Init()
Dim i As Integer
Dim angle As Double
getPixelCalls = 0
ReDim cSinA(cSteps - 1)
ReDim cCosA(cSteps - 1)
For i = 0 To cSteps - 1
angle = GetAlpha(i) * Math.PI / 180.0#
cSinA(i) = Math.Sin(angle)
cCosA(i) = Math.Cos(angle)
Next
cDMin = -cBmp.Width
cDCount = 2 * (cBmp.Width + cBmp.Height) / cDStep
ReDim cHMatrix(cDCount * cSteps)
End Sub
Public Function GetAlpha(ByVal Index As Integer) As Double
Return cAlphaStart + Index * cAlphaStep
End Function
End Class
|
|
|
|
|
Hello guys!
I am trying to use the following code to send an email to a mail server over a tcp connection. The code works great, however, when I try to send an email to someone, the receipt of my Email alwyes gets unknown sender(From). Am I missing something?
TcpClient SmtpServ = new TcpClient("smtp.my.com", 25);
string Data;
byte[] szData;
string CRLF = "\r\n";
try
{
NetworkStream NetStrm = SmtpServ.GetStream();
StreamReader RdStrm = new StreamReader(SmtpServ.GetStream());
Console.WriteLine(RdStrm.ReadLine());
Data = "HELO server" + CRLF;
szData = System.Text.Encoding.ASCII.GetBytes(Data.ToCharArray());
NetStrm.Write(szData, 0, szData.Length);
Console.WriteLine(RdStrm.ReadLine());
Data = "MAIL From:" + " me@test.com" + CRLF;
szData = System.Text.Encoding.ASCII.GetBytes(Data.ToCharArray());
NetStrm.Write(szData, 0, szData.Length);
Console.WriteLine(RdStrm.ReadLine());
Data = "RCPT TO: " + "me@my.net" + CRLF;
szData = System.Text.Encoding.ASCII.GetBytes(Data.ToCharArray());
NetStrm.Write(szData, 0, szData.Length);
Console.WriteLine(RdStrm.ReadLine());
Data = "DATA" + CRLF;
szData = System.Text.Encoding.ASCII.GetBytes(Data.ToCharArray());
NetStrm.Write(szData, 0, szData.Length);
Console.WriteLine(RdStrm.ReadLine());
Data = "SUBJECT: my subject\r\n\r\n";
Data += "Hello there!\r\n";
Data += ".\r\n";
szData = System.Text.Encoding.ASCII.GetBytes(Data.ToCharArray());
NetStrm.Write(szData, 0, szData.Length);
Console.WriteLine(RdStrm.ReadLine());
Data = "QUIT" + CRLF;
szData = System.Text.Encoding.ASCII.GetBytes(Data.ToCharArray());
NetStrm.Write(szData, 0, szData.Length);
Console.WriteLine(RdStrm.ReadLine());
NetStrm.Close();
RdStrm.Close();
Console.WriteLine("Close connection");
Console.WriteLine("Send mail successly..");
}
catch (InvalidOperationException err)
{
Console.WriteLine("Error: " + err.ToString());
}
Thanks,
|
|
|
|
|
The email address in the MAIL FROM: and RCPT TO: lines should be bounded with < and > characters like this:
"MAIL From:" + " <me@test.com>" + CRLF;
I also notice that you are ignoring all server responses so you cannot be sure your message is being accepted correctly. You may also like to consider using the SmtpClient() [^] class to process your mail.
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
Hello Guys,
We are developing an antispyware program in .net and i want to register my product for listing it into windows security center. I Searched a lot about it and got some idea that it can be done through WMI by \\root\SecurityCenter2 namespace and antispywareproduct class. But all i found was to get the information for antispywareproduct class.
Can any one tell me how to add my product to this table.
any ideas will be a great help.
Regards
abhinav
|
|
|
|
|
Hello all,
I found this link .NET TWAIN image scanner[^] on code project, but When I press acuqire it opens a window from my scanner
when I press cancel on it, the whole application get freezed. How to solve this???
plzz
Thx
|
|
|
|
|
The best place to ask that is in the forum at the bottom of the mentioned article.
If you post there, the author will be notified. He is the person that more likely than others can help you.
Ciao,
luker
|
|
|
|
|
Hi all.
I'm now developing a website that connect to Postgre SQL database. I used NpgSQL.DLL to connect from C# to database. I also finished testing this project in my local pc, it worked well. But unfortunately it did not work well in server. Some errors in connecting to server happened.
These errors happened when website had much people logged in and began using database query functions ( select, update, delete .. ). I think errors begin from codes in connect database functions. but i still can not fix it. this is my connecting database codes.
------ codes connects database ---------
-- Connect.cs file.
public static void connectDB()
{
try
{
conn.ConnectionString = connection;
conn.Open();
}
catch
{
}
}
public static void closeConnectDB()
{
conn.Close();
}
public static int ExecuteQuery(string SQL)
{
try
{
connectDB();
NpgsqlCommand cmd = new NpgsqlCommand(SQL, conn);
return cmd.ExecuteNonQuery();
}
catch
{
closeConnectDB();
return 0;
}
}
public static DataSet SelectQuery(string SQL)
{
DataSet ds = new DataSet();
try
{
connectDB();
NpgsqlDataAdapter nDa = new NpgsqlDataAdapter(SQL, conn);
nDa.Fill(ds);
return ds;
}
catch
{
closeConnectDB();
return ds;
}
}
----------------- use to execute these codes --------
....
--- calling functions files.
try
{
string strTest = "Select * from abc where .. ";
DataSet ds1 = new DataSet();
ds1 = Connect.SelectQuery(strTest);
if (ds1.Tables[0].Rows.Count > 0)
{
}
else
{
int kq = Connect.ExecuteQuery(strInsert);
if (kq > 0)
{
int kk = Connect.ExecuteQuery(strUpdate);
kk = Connect.ExecuteQuery(strUpdate2);
strHTML = "OK";
}
}
}
catch
{
strHTML = "errors.";
}
finally
{
int kk = Connect.ExecuteQuery(strUpdate);
kk = Connect.ExecuteQuery(strUpdate2);
strHTML += "-- Sub Finally";
}
-----------------End calling function---------------
Here sometimes it worked well but sometimes catched errors.
Can you help me? thanks and regards.
|
|
|
|
|
Don't just swallow exceptions, at the very least you should log them to console or a log file so you can look at the stack trace and exception message. Those error messages will almost certainly give you a big clue as to the problem.
|
|
|
|
|
Hi everyone,
I want to integrate a C# application for paperless billing with a retail billing machine (those which are used in shopping malls for generating bills). Is there any way it can be done? Did not get any information about it on Google.
-Please help.
|
|
|
|
|
tahernd wrote: I want to integrate a C# application for paperless billing with a retail billing machine
What software exists in this machine and what interface(s) does it provide (both software and hardware) for connection with other applications?
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|