|
Hi All,
i've a tricky little problem with AutoScroll functionality that i can't seem to overcome. I have a panel with its autoscroll property set to true. On the panel i have several combo boxes which are surrounded by some graphics implemented with GDI+. My problem is as follows .. say a combo box at the bottom of the panel has focus, when i click on the panel i want it to gain focus but not refresh and redraw itself at its initial position i.e. (0,0). In other words when the panel gets focus i still want to be able to view the combo box at the bottom of the panel which had previously been the active control.
Is there any way of preventing the panel from redrawing itself at its initial (0,0) position???
Or is it possible to calculate the autoscroll position prior to giving the panel focus then explicitly setting the autoscroll position to the desired position.
Any ideas and suggestions are very welcome and appreciated!
Thanks,
Paul Griffin
|
|
|
|
|
Simple math and the ScrollableControl.AutoScrollPosition (inheritted by derivative classes like Panel ). Just be sure to read the .NET Framework SDK documentation about when to use client- and screen-based coordinates (which can be easily converted using methods like Control.PointToClient and Control.PointToScreen ).
If you have a ComboBox that is partly hidden and want to make sure that it's completely visible without scrolling it to the client point 0,0 for its container, find out how much is hidden and offset the current AutoScrollPosition by that amount:
int offset = comboBox1.Bottom - this.Height;
Point p = this.AutoScrollPosition;
p.X -= offset;
this.AutoScrollPosition = p; This is only an example, but hopefully gives you some idea. Also, do not simple set AutoScrollPosition.X to something. A Point is a value type - not a reference type - and needs to be copied first before being modified. If you set AutoScrollPosition.X to some offset, you'll notice no change because a copy was made but never assigned to AutoScrollPosition again.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles]
|
|
|
|
|
Hi Heath,
thanks for your response! Your suggestion is actually the way i had approached the problem. In the MouseDown event handler for my panel i create a vertical offset from the MouseEventArgs e.Y. as follows:
int offset = e.Y ;<br />
this.myPanel.Focus();<br />
<br />
Point p = this.myPanel.AutoScrollPosition;<br />
p.Y = offset;<br />
this.myPanel.AutoScrollPosition = p;
When i debug the code i see that p does get initialised to the correct value but the assignment to AutoScrollPosition never works. AutoScrollPosition always remains (0,0)???
Any ideas as to what is happening here??
Thanks again!
Paul Griffin
|
|
|
|
|
Your offset isn't an offset at all. You need to off-set the current Point (the AutoScrollPosition ) by a certain amount like I did in my example. What you're doing now would make the Location of your control scroll to the top which would be 0,0 (the position within the container control).
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles]
|
|
|
|
|
Hi Heath,
sorry if i seem to be missing the point! Perhaps i need to re-phrase what it is i'm trying to accomplish. I'm trying to get a panel with AutoScroll set to true to scroll to a certain location i.e. the location last clicked before i gave focus to the panel thus causing it to redraw at its initial position.
No in your example you use this.AutoScrollPosition = p;
i assume for me this would be mypanel.AutoScrollPosition = p;
but when i do this and debug it if i step over the assignment the AutoScrollPosition value = (0,0);
so i understand that i need to offset the AutoScrollPosition .. i just can't seem to get it to change from (0,0)
again i appreciate your help here! this is starting to drive me mad!
Paul Griffin
|
|
|
|
|
It's what you do to the Point before assigning it back to mypanel.AutoScrollPosition that matters. If you haven't already, read about the ScrollableControl.AutoScrollPosition and pay close attention to the the note just before the example.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles]
|
|
|
|
|
Hi Heath,
just to let you know i finally cracked it, a combination of thinking about your posts properly and spotting a very stupid mistake i was making.
Thanks a lot for your replies!
Paul Griffin
|
|
|
|
|
Reading that back still didn't sound right i'll try one more time.
The sequence of events are as follows:
1. My panel receives focus and using the mouse wheel or scroll bar itself i scroll to some point on the panel.
2. I click on a second control e.g. a combo box.
3. I'm now finished using the combo box and i would like the panel to regain focus so that i can continue scrolling it.
4. I click back onto the panel, the panel_MouseDown event handler fires in which i include the line panel.Focus();
Problem:
Each time this line is executed the panel redraws itself with the scrollbar at its initial position and i have to scroll all the way down to where i was before i can continue to the next control lower down on the panel.
May sound like a trivial problem but as i've said repeatedly the functionality to set the scroll bar position explicitly doesn't seem to be there!
There hope that describes the situation a bit more clearly!
Paul Griffin
|
|
|
|
|
Hi everybody,
I am developing a game for a pocket pc. There are picture boxes with images loaded @ runtime that forms a rectangle like shape.
How u play is , u have to create chains(draw line) combining images of same type (there are 4 types of images). To do this I need to find the shortest path between 2 images and the path should not be blocked by any other type of image.
A line also need to be drawn joining the images.
Can anyone please help me!!!!!!!!!!!!!!!!!!!!!
Thanks
Casper
|
|
|
|
|
Hi,
I am developing a game for a pocket pc. There are picture boxes with images loaded @ runtime that forms a rectangle like shape.
How u play is , u have to create chains(draw line) combining images of same type (there are 4 types of images). To do this I need to find the shortest path between 2 images and the path should not be blocked by any other type of image.
A line also need to be drawn joining the images.
Can u please help me!!!!!!!!!!!!!!!!!!!!!
Thanks
|
|
|
|
|
Have a look at C# : A-Star is born or at Quickgraph
Or look for "Dijkstra algorithm" on google.
Maybe post/send some code to explain the situation... curous as how it all looks myself.
|
|
|
|
|
I had a previous post regarding how to design a socket based client-server system with C#.net which will scale very well. http://www.codeproject.com/script/comments/forums.asp?msg=913692&forumid=1649#xx913692xx[^]
Heath gave a very interesting response, which told me:
(1) Use Web Services or .net remoting to free yourself from the socket level details
(2) Try to use WSE DIME for file transfers
I am reading on these.
A further question in this context:
I have observed that many clients do not allow incoming http connections inside their firewall. They typically have the DMZ firewall configuration. The Web Server will be in the DMZ and app servers will be inside. They also do not permit to have their business logic sitting on the IIS machine.
So even though I have a Web service based entry to my system, it still has to do socket communication with my server sitting inside the firewall over an admin allowed port.
Browser/WinForm Clients
<->DMZ<-> [Allows only http]
Web Service (IIS)
<->Firewall<-> [Allows only my chosen port]
My Server (With DB/NTFS/Network access)
Am I missing something? Are there any better options?
|
|
|
|
|
In the scenario you described, your solution is correct. But again don't consider simple socket communications. .NET Remoting can work over any port without IIS, you just need a different host. Windows Services, for example (those deriving from ServiceBase and installed with the ServiceInstaller and ServiceProcessInstaller classes), make great hosts.
The solution depends entirely on your network topology. If your external web servers sits in a DMZ and has limited access to the inside network through well-known ports (like HTTP), then one solution is to use .NET Remoting or Web Services to talk to an internal web server (perhaps a virtual end-point for SQL Server, even) through port 80 (or whatever port the web server is configured on).
There's not a single solution for any given scenario.
To learn more about .NET Remoting, I recommend picking up "Microsoft .NET Remoting" from Microsoft Press[^] or "Advanced .NET Remoting" from Ingo Rammer[^], both very good books (although the latter is for intermediate and advanced .NET Remoting developers, while the former is for beginning and intermediate .NET Remoting developers).
The only point I was making before was that the wire protocol isn't enough. You still need to define a data transfer protocol with any application and platform. .NET Remoting and Web Services (which are an industry standard and not specific to .NET) describe both. .NET Remoting is comrised of independant wire and transfer protocols (i.e., binary or SOAP over HTTP or TCP - "out of the box"), while Web Services use SOAP over HTTP.
If you want to use sockets, you'll need to define your own protocols.
This also depends on legacy systems, too. If you have a legacy socket server in place and want to continue using it, then you'll have to use the protocol you already defined with the socket classes in the BCL.
The nice thing about Web Services is, though, that many legacy servers now support HTTP daemons, which aren't too hard to implement (basically) anyway. Developing a Web Services need not be hard, either, so long as you explore the SOAP and WSDL specifications and implement them accordingly. I've seem scenarios where older AS/400s implemented Web Services. IBM was a key player in the push for Web Services, so many of their upgraded OS images support them through WebSphere or some other system (I must admit I don't follow IBM these days).
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles]
|
|
|
|
|
I tried to do some C# for the first time and decided
to try and use one of my C++ COM classes from it.
Using the class from C# gives this definition of a method.
MyInterface1.A(out MyInterface2 ppIFace)
Trying to call it as this will fail with a syntax error.
MyInterface2 IFace2;
MyInterface1 IFace1;
IFace1.A(IFace2)
How do i call this method from C# ?
/Magnus
- I don't necessarily agree with everything I say
|
|
|
|
|
With C# you'll have to specify if a parameter is a ref or out parameter not only at the method declaration but at every call.
So writing
IFace1.A(out IFace2); should do the trick.
Regards,
mav
|
|
|
|
|
Oh..that simple, thanks.
/Magnus
- I don't necessarily agree with everything I say
|
|
|
|
|
In Web Application, Use File.Exists(filename) method,don't find the file that in network folder?
|
|
|
|
|
That is kind of a generic question but it should. Why not try it and find out instead of asking here? ![Smile | :)](https://codeproject.global.ssl.fastly.net/script/Forums/Images/smiley_smile.gif)
|
|
|
|
|
File.Exists works on physical files. In an ASP.NET web application (or even an ASP web application, or many other web application frameworks), paths are virtual. They map to a physical path but not automatically.
To map a virtual path to a physical path in ASP.NET, use Server.MapPath or Page.MapPath depending on your context. If your code was in a page, for example, you would use:
if (File.Exists(MapPath("/path/to/file.aspx")))
In the future, please direct ASP.NET-related questions to the ASP.NET forum regardless of what language you're using. The ASP.NET forum is specifically for ASP.NET-related questions.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles]
|
|
|
|
|
An issue to consider: asp.net runs (by default) under a user account on the local machine (the web server, that is.). Chances are good that this account does not have access to the files you are trying to reach on the network folder, so Exists() will always return false.
The only solution I've found if I REALLY need to access files across the network from within asp.net code is to impersonate. Since this is a little involved, I am not going to take up community bandwidth unless you are sure this is what you need to do.
It would make life much easier if you can get all the files onto the webserver. If you cannot, please post if you need details, I'll post an example.
Hope this helps,
Bill
|
|
|
|
|
Hello,
I want to develop a little Smart Device Application for my Pocket Pc with a little database. further when i developed the application i want to synchronise the database of the PocketPc with the database on my desktop. Does anybody have to these problems any code samples or literature and/or can give me further help?
thx
regards
|
|
|
|
|
Hi,
I've created an app which adds rows to a table, which I view in a DataGrid. But the application hangs after a while, especially if I move the window around. Does anyone know how to get around this problem. I'm using a thread that once a second adds a row to the table, and I think that the DataGrid or something surrounding it is not threadsafe. I am quite surprised that it is not threadsafe, but maybe there is something underneath it all that explains it.
I've put together a testcase where this is happening, see below.
Any pointers are welcome.
Regards
Tobias
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Threading;
namespace DataGridTest2
{
///
/// Summary description for Form1.
///
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.TabControl tabControl1;
private System.Windows.Forms.TabPage tabPage1;
private System.Windows.Forms.TabPage tabPage2;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.DataGrid dataGrid1;
///
/// Required designer variable.
///
private System.ComponentModel.Container components = null;
private System.Data.DataTable rLogDataTable = null;
private System.Data.DataSet rDataSet = null;
private DateTime rStartTimeStamp;
private int index = 0;
private Thread rResponseThread = null;
public Form1()
{
rStartTimeStamp = DateTime.Now;
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
createLogDataTable();
dataGrid1.SetDataBinding( rDataSet, "Log" );
rResponseThread = new Thread( new ThreadStart( this.responseThread ) );
rResponseThread.Start();
}
///
/// Clean up any resources being used.
///
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
rResponseThread.Abort();
}
#region Windows Form Designer generated code
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///
private void InitializeComponent()
{
this.tabControl1 = new System.Windows.Forms.TabControl();
this.tabPage1 = new System.Windows.Forms.TabPage();
this.tabPage2 = new System.Windows.Forms.TabPage();
this.button1 = new System.Windows.Forms.Button();
this.dataGrid1 = new System.Windows.Forms.DataGrid();
this.tabControl1.SuspendLayout();
this.tabPage1.SuspendLayout();
this.tabPage2.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).BeginInit();
this.SuspendLayout();
//
// tabControl1
//
this.tabControl1.Controls.Add(this.tabPage1);
this.tabControl1.Controls.Add(this.tabPage2);
this.tabControl1.Location = new System.Drawing.Point(32, 48);
this.tabControl1.Name = "tabControl1";
this.tabControl1.SelectedIndex = 0;
this.tabControl1.Size = new System.Drawing.Size(624, 568);
this.tabControl1.TabIndex = 0;
//
// tabPage1
//
this.tabPage1.Controls.Add(this.button1);
this.tabPage1.Location = new System.Drawing.Point(4, 22);
this.tabPage1.Name = "tabPage1";
this.tabPage1.Size = new System.Drawing.Size(616, 542);
this.tabPage1.TabIndex = 0;
this.tabPage1.Text = "tabPage1";
//
// tabPage2
//
this.tabPage2.Controls.Add(this.dataGrid1);
this.tabPage2.Location = new System.Drawing.Point(4, 22);
this.tabPage2.Name = "tabPage2";
this.tabPage2.Size = new System.Drawing.Size(616, 542);
this.tabPage2.TabIndex = 1;
this.tabPage2.Text = "tabPage2";
//
// button1
//
this.button1.Location = new System.Drawing.Point(104, 112);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(272, 120);
this.button1.TabIndex = 0;
this.button1.Text = "Add Item To Grid";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// dataGrid1
//
this.dataGrid1.DataMember = "";
this.dataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText;
this.dataGrid1.Location = new System.Drawing.Point(16, 24);
this.dataGrid1.Name = "dataGrid1";
this.dataGrid1.Size = new System.Drawing.Size(584, 496);
this.dataGrid1.TabIndex = 0;
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(688, 646);
this.Controls.Add(this.tabControl1);
this.Name = "Form1";
this.Text = "Form1";
this.tabControl1.ResumeLayout(false);
this.tabPage1.ResumeLayout(false);
this.tabPage2.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit();
this.ResumeLayout(false);
}
#endregion
///
/// The main entry point for the application.
///
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void button1_Click(object sender, System.EventArgs e)
{
DateTime rTmp = DateTime.Now;
TimeSpan rTimeDiff = rTmp - rStartTimeStamp;
this.addToLog( ""+(index++), "test", rTimeDiff );
}
private void addToLog( string sID, string sEvent, TimeSpan rTS )
{
DataRow myDataRow = rLogDataTable.NewRow();
myDataRow["ID"] = sID;
myDataRow["Event"] = sEvent;
myDataRow["TimeDiff"] = rTS;
rLogDataTable.Rows.Add(myDataRow);
}
private void createLogDataTable()
{
// Create a new DataTable.
rLogDataTable = new DataTable("Log");
// Declare variables for DataColumn and DataRow objects.
DataColumn myDataColumn;
// Create new DataColumn, set DataType, ColumnName and add to DataTable.
//
// The ID
myDataColumn = new DataColumn();
myDataColumn.DataType = System.Type.GetType("System.String");
myDataColumn.ColumnName = "ID";
myDataColumn.AutoIncrement = false;
myDataColumn.ReadOnly = false;
myDataColumn.Unique = false;
// Add the Column to the DataColumnCollection.
rLogDataTable.Columns.Add(myDataColumn);
//
// The Event
myDataColumn = new DataColumn();
myDataColumn.DataType = System.Type.GetType("System.String");
myDataColumn.ColumnName = "Event";
myDataColumn.AutoIncrement = false;
myDataColumn.Caption = "ParentItem";
myDataColumn.ReadOnly = false;
myDataColumn.Unique = false;
// Add the column to the table.
rLogDataTable.Columns.Add(myDataColumn);
//
// The Time-string
myDataColumn = new DataColumn();
myDataColumn.DataType = System.Type.GetType("System.TimeSpan");
myDataColumn.ColumnName = "TimeDiff";
myDataColumn.AutoIncrement = false;
myDataColumn.Caption = "ParentItem";
myDataColumn.ReadOnly = false;
myDataColumn.Unique = false;
// Add the column to the table.
rLogDataTable.Columns.Add(myDataColumn);
// Instantiate the DataSet variable.
rDataSet = new DataSet();
// Add the new DataTable to the DataSet.
rDataSet.Tables.Add(rLogDataTable);
}
private void responseThread()
{
string sThreadName = "ResponsePollingThread";
Thread.CurrentThread.Name = sThreadName;
string sTmp = null;
string sSeparator = "\n*************************************\n";
bool found = false;
string searchstring = null;
try
{
while( true )
{
DateTime rTmp = DateTime.Now;
TimeSpan rTimeDiff = rTmp - rStartTimeStamp;
this.addToLog( ""+(index++), "thread", rTimeDiff );
Thread.Sleep( 1000 );
}
}
catch( Exception e )
{
// Console.WriteLine( "Exception in "+sThreadName+", exception; "+e );
Console.WriteLine( "Updater-thread ended." );
}
}
}
}
|
|
|
|
|
i dont think _any_ winforms controls are to be considered thread safe..
use .BeginInvoke or such to marshal teh calls into the main thread and manipulate teh controls there.
//Roger
|
|
|
|
|
Hi,
Now I've implemented a solution which seems to work fine.
This is what I needed to do:
1) Create a 'delegate' which had the same signature as my addToLog(...)-method.
public delegate void myDelegate( string id, string e, TimeSpan ts );
2) Modify the responseThread()-method so that it creates the delegate
myDelegate md = new myDelegate( addToLog );
3) Modify the responseThread()-method so that it calls (or more accurately invokes) the delegate with the appropriate arguments:
so the line that before said:
this.addToLog( ""+(index++), "thread", rTimeDiff );
Now says:
this.Invoke( md, new Object[] { ""+(index++), "thread", rTimeDiff } );
private void responseThread() <br />
{ <br />
string sThreadName = "ResponsePollingThread";<br />
Thread.CurrentThread.Name = sThreadName;<br />
string sTmp = null;<br />
string sSeparator = "\n*************************************\n";<br />
bool found = false;<br />
string searchstring = null;<br />
myDelegate md = new myDelegate( addToLog );<br />
try <br />
{<br />
while( true ) <br />
{<br />
DateTime rTmp = DateTime.Now;<br />
TimeSpan rTimeDiff = rTmp - rStartTimeStamp;<br />
this.Invoke( md, new Object[] { ""+(index++), "thread", rTimeDiff } );<br />
Thread.Sleep( 1000 );<br />
}<br />
}<br />
catch( Exception e ) <br />
{<br />
Console.WriteLine( "Updater-thread ended." );<br />
}<br />
}
|
|
|
|
|
Ok so here's my question:
Does anyone know how to make (in C# of course) a child window that has focus at the same time the parent form does *and* exists outside of the main parent form.
I don't want MDI because it requires the child form to sit inside of the main parent form. I know it's doable in the Windows environment since I have two programs that do this (Photoshop and Flash). Their tool palettes can be clicked on and they do not tear away focus from the main form on the desktop.
I suppose I can cheat and whenever someone clicks on a button inside of the toolpalette (i.e. the child form), call Focus() on the parent form. But like I say I know in the Windows environment it is possible to have both maintain focus. Since Photoshop and Flash both do it.
Does anyone know a way around this? Any help would of course be most valuable and appreciated.
![Smile | :)](https://codeproject.global.ssl.fastly.net/script/Forums/Images/smiley_smile.gif)
|
|
|
|
|