|
I need to position a form in certain place. Supposed I have a form named "form1", I did this:
form1.StartPosition = FormStartPosition.Manual;
form1.Location = new Point( 100, 100 );
But it doesn't work. The form1 just keep staying at (0, 0). Can anyone tell me why?
Thanks in advance!
|
|
|
|
|
sorry, There's a bug in my program. Now is ok. Thanks for reading.
|
|
|
|
|
How to bind a ComboBox to an valuable? Such as, I want to bind the ComboBox.SelectedItem and another valuable(string s) together. How can I do that?
Thanks!
|
|
|
|
|
I'm not sure I fully understand your problem. Btw look at MSDN
library: (ex: ComboBox.DataSource).
Using DataSource property to associate a collection to your ComboBox, you have both a "DisplayMember" property, and a "ValueMember" property. I think this will solve your problem.
Gilles
|
|
|
|
|
Sorry, I didn't make myself very clear. Thank you for answering and I got confused about this for a long time.
But now my problem is: I want to connect a valuable and a combobox together. when the valuable changes, the selection of combobox changes too. on the other hand, when the selection of combobox change, this valuable will change too.
But I don't know how to do that in C#. Do you have any ideas about this one?
Thanks in advance.
|
|
|
|
|
a value or a variable
ComboBox1 has its own items including ID which dictates COmboBox2
Table1
CustomerName
CustomerID
Table2
StoreName
StoreID
CustomerID
As you can see the relationship is a customer has 0 or many stores and a store must have 1 customer
ComboBox1.DataSource = Table["CUstomer"].DefaultView;
ComboBox1.DisplayMember = "Name";
ComboBox1.ValueMember = "ID";
ComboBox2.DataSource = Table["Stores"].DefaultView;
ComboBox2.DisplayMember = "Name";
ComboBox2.ValueMember = ComboBox1.SelectedValue;
try that out, when you change combo1 the combo2 is updated based on the relationshipID.
to make them change each other makes no sense really, its a circular relationship which would require for you to hand pick the relationships in which
you would sink the SelectedIndex_Changed event and make your changes there.
nick
I'm not an expert yet, but I play one at work. Yeah and here too.
|
|
|
|
|
I wrote the code using DataBindings like that:
checkBox1.DataBindings.Add("Checked", MyClass, "bValue" );
"checkBox1.Checked" and MyClass.bValue were supposed to be changed whenever the other one was changed.
But, when I changed the value of check1.Checked, like this:
checkBox1.Checked = false;
MyClass.Value was not changed.
Can anyone tell me why?
Thanks in advance!
|
|
|
|
|
what does more code look like?
I mean does your class have get and set accessors. dont use public fields because you need to validate the data. what if a null comes from a database or somewhere. your code will break.
nick
I'm not an expert yet, but I play one at work. Yeah and here too.
|
|
|
|
|
I am trying to automate login to a site for a subsequent file upload. Even though I set the Content-Length header I keep getting the 411 (length required) response error.
I begin with an initial unauthorized request to a form-authenticated page.
I extract the session cookie from the response header and attach it to the next request I send by POST method, along with the required authentication info. The program halts as soon as I try to access the next response, referring to the abovementioned error code.
Please tell me what I'm missing...
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
using System;
using System.Net;
using System.Web;
using System.Text;
using System.IO;
public class Loader {
private HttpWebRequest request;
private HttpWebResponse response;
private CookieCollection cookies;
private string url = "http://www.somedomain.com/member/home.jsp";
private string logPath = @"c:\\loader\response.log";
/*-------------------------------------------------------------------------*/
public static void Main() {
Loader loader = new Loader();
loader.MakeInitRequest();
loader.SendAuthInfo();
} // end Main
/*-------------------------------------------------------------------------*/
public void MakeInitRequest() {
request = (HttpWebRequest) WebRequest.Create(url);
// Set the request's CookieContainer
request.CookieContainer = new CookieContainer();
response = (HttpWebResponse) request.GetResponse();
// Capture cookies from the initial response
cookies = response.Cookies;
// Log the response
this.LogResponse("\n\n************INITIAL RESPONSE:************\n\n");
response.Close();
} // end MakeInitRequest
/*-------------------------------------------------------------------------*/
public void SendAuthInfo() {
string username = "my_username";
string password = "my_password";
string postData = "j_username=" + HttpUtility.UrlEncode(username) +
"&j_password=" + HttpUtility.UrlEncode(password);
byte[] postDataBytes = Encoding.ASCII.GetBytes(postData);
request = (HttpWebRequest) WebRequest.Create(url);
// Set the cookies from the initial response to this request
if (cookies != null) {
request.CookieContainer = new CookieContainer();
request.CookieContainer.Add(cookies);
}
// Set the request headers
request.Method = "POST";
request.ContentType = "application-www-form-urlencoded";
request.ContentLength = postDataBytes.Length;
// Post authentication info
StreamWriter writer = new StreamWriter( request.GetRequestStream() );
writer.Write(postDataBytes);
// Log the response
response = (HttpWebResponse) request.GetResponse();
this.LogResponse("\n\n************NEXT RESPONSE************\n\n");
response.Close();
writer.Close();
} // end SendAuthInfo
/*-------------------------------------------------------------------------*/
private string DisplayResponseHeaders(WebHeaderCollection headers) {
StringBuilder buffer = new StringBuilder();
// Capture each header:value pair
foreach(string header in headers) {
buffer.Append(header + ": " + headers[header] + "\n");
}
return buffer.ToString();
} // end DisplayResponseHeaders
/*-------------------------------------------------------------------------*/
private void LogResponse(string title) {
FileStream fStream =
new FileStream(logPath, FileMode.Append, FileAccess.Write);
StreamWriter logWriter = new StreamWriter(fStream);
StreamReader reader = new StreamReader(response.GetResponseStream());
string responseString;
// Log the response
responseString =
this.DisplayResponseHeaders(response.Headers) +
reader.ReadToEnd();
logWriter.Write(title + responseString);
reader.Close();
logWriter.Close();
fStream.Close();
} // end LogResponse
/*-------------------------------------------------------------------------*/
} // end class Loader
|
|
|
|
|
|
I have created a Database Object on a Remoting Server that is not disposing when the function call is returned? Why would this be happening?
|
|
|
|
|
Yes how can i override the drawing inside the row header
nick
I'm not an expert yet, but I play one at work. Yeah and here too.
|
|
|
|
|
Hi all.
I've searched through the forums but couldn't find an answer.
I have a rich text box (but the question stands even for "simple" text boxes),
and I would like to get the cursor's position within it.
Something like "line X column Y", or even just "char Z".
Any suggestions?
In particular, I'm trying to get to this info from the
handler of a mouse click event on the rich text box
--just in case the System.Windows.Forms.MouseEventArgs parameter can help
Thanks in advance,
F.O.R.
|
|
|
|
|
Well, so far here's what I found... if anyone has any better idea, feel free to post
<br />
<br />
int ndex = this.rBox_MarkedUp.GetCharIndexFromPosition(<br />
new System.Drawing.Point(e.X, e.Y));<br />
int line = this.rBox_MarkedUp.GetLineFromCharIndex(ndex);<br />
ndex is now the 0-based index of the char clicked
and
line is the number of the line (0-based as well).
We now return to the usual stream of questions
Thanks,
F.O.R.
|
|
|
|
|
Hi.
I just went thru this as well, but this is what i worked out. it's basically the same thing you already figured out.
private void rtb1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)<br />
{<br />
leftMouse(e.X, e.Y);<br />
}<br />
<br />
private void leftMouse(int X, int Y)<br />
{<br />
posStart = rtb1.GetCharIndexFromPosition(new Point(X, Y));<br />
}
|
|
|
|
|
Can you use functions like sprintf in c#??
If so, what namespace would you need to use them??
Because you can't do #include <stdio.h>
Or can you???!!!!????
|
|
|
|
|
Why not just use String.Format?
|
|
|
|
|
There is a nice section in the C Runtime Lib docs on MSDN that shows you exactly how the functions maps. Sorry no link.
leppie::AllocCPArticle("Zee blog");
|
|
|
|
|
|
Hi !
I'm new to this whole .NET framework stuff. I want to implement "Office XP Task Panel" like functionality and
how to attached two windows.
Thanks & Regards
Sanjay Rastogi
|
|
|
|
|
Dear sirs,
I would like to get more information about SingleCall servers like:
1- Is it possible to persist data in SingleCall server ? If so, how ?
2- Is it possible to keep a thread running indefinitly in a SingleCall
server ?
3- I need to develop a SingleCall server that keep several threads
running, to monitor something, like a Process Scheduler, for example.
My questions are:
- When (and where) do I need to start them ?
- When (and where) do I need to stop them ?
- How long will them still running ?
4- In a SingleCall server, is it possible to share data among server
calls using static variables ?
Thank you very much.
Marcos.
|
|
|
|
|
Hi friends,
Is there any new class,namespace now available with C# to invoke win32 APIs like SendMessage?
VikramS
|
|
|
|
|
You can easily declare Windows APIs in your code. For instance, SendMessage would be:
[DllImport("user32.dll")]
public static extern int SendMessage(IntPtr hWnd, int msg, int wParam, int lParam);
This article[^] has a large number of Win32 constants, functions, and structures declared.
"Blessed are the peacemakers, for they shall be called sons of God." - Jesus
"You must be the change you wish to see in the world." - Mahatma Gandhi
|
|
|
|
|
I'm having a little difficulty with the set accessor. I'm working on a template-based site design and trying to use the set accessor to set the document's title. The problem is that it's not setting the title and I can't seem to figure out what I'm missing. Here's some sample code:
---
ControlBase.cs
---
public class ControlBase : System.Web.UI.UserControl
{
private string _strTitle;
public string Title
{
get
{
return _strTitle;
}
set
{
_strTitle = value;
}
}
}
---
Default.aspx
---
<%@ Page language="c#" Codebehind="Default.aspx.cs" AutoEventWireup="false"
Inherits="namespace.PageBase" %>
...
<title><asp:literal id="litTitle" runat="server"></asp:literal></title>
---
Default.aspx.cs
---
public class PageBase : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Literal litTitle;
private ControlBase _ctlContent;
private void Page_PreRender(object sender, System.EventArgs e)
{
if (_ctlContent.Title != string.Empty)
{
this.litTitle.Text = _ctlContent.Title;
}
}
}
---
Default.ascx.cs
---
public class Default : ControlBase
{
private void Page_Load(object sender, System.EventArgs e)
{
this.Title = "This should be the title of the document";
}
}
|
|
|
|
|
your class is fine. its how your populating it freom the asp page is the problem.
nick
I'm not an expert yet, but I play one at work. Yeah and here too.
|
|
|
|