|
If form2 is insanciated from form1, then you can set form2's location property after creating form2 but before calling it's show method. Make sure form2's StartPosition is set to Manual.
If not, you could use the project's settings to save the position of form1, and retrieve those settings in form2's constructor.
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 Dave,
Thanks for the reply.
Do you think it would be possible if you could write some example code for me, just to get a better understanding of the solutions you have supplied?
Sorry, like I said I am very new to C# and programming in general. :/
Thanks again for the reply.
|
|
|
|
|
This will help you more. Find some keywords here and Google it, it will give you some code, and explain what you are doing.
You need to create an instance of Form2 from Form1. Then get Form1's position, and set Form2's position to the same. Finally, show Form2.
You should be able to get started with those steps.
The best way to accelerate a Macintosh is at 9.8m/sec² - Marcus Dolengo
|
|
|
|
|
Thanks so much, will update with my progress.
|
|
|
|
|
The first one is pretty simple. Somewhere in your Form1 code you will have something like this:
Form2 form2 = new Form2();
form2.Show(); Just insert
form2.Location = this.Location;
in between.
The second, you will need to create a setting in your project's properties of type System.Drawing.Point . On each Move event (you'll need to subscribe to the event) handling method in Form1, set your setting:
Properties.Settings.Default.YourSettingName = this.Location; and after the InitializeComponent call in Form2, retrieve the setting:
this.Location = Properties.Settings.Default.YourSettingName;
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 Dave,
I cannot believe how simple this solution really is - thank you so much.
I am still getting to terms with the jargon and so on, I was so close!
private void btnOpenForm2_Click_1(object sender, EventArgs e)
{
if (form2 == null || form2.IsDisposed)
{
form2 = new Form2();
form2.Location = this.Location; < ----- I just had to add this
this.Visible = false;
form2.Show();
}
else
{
MessageBox.Show("form2 already open,showing");
form2.Focus();
}
}
I also had to change form2's start position within the code for form2, to
this.StartPosition = System.Windows.Forms.FormStartPosition.Manual;
Thanks so much again for the help, I really appreciate it!
|
|
|
|
|
Paulo Toureiro wrote: I also had to change form2's start position within the code
That can be done from the designer instead so it's serialized into the Form2.Designer.cs file automatically.
Paulo Toureiro wrote: Thanks so much again
No problem
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)
|
|
|
|
|
I want to know how to do that. I can use foreach and for loop, but I prefer to use the array class.
Assume I have my array like
int[] arrayData = { 1, 3, 5, 0, 6 };
By using .All generic method, it is possible to do something like that to determine if all elements are zero
arrayData.All
So how can I use the .All to determine if all elements in the array is 0
|
|
|
|
|
The MSDN has samples, but basically you write a predicate method that returns what you want to return. For example, a search method would involve you writing the code that checks each element. Under the hood, it's not much different at the end of the day, the code that runs will use for each to check each element.
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
arrayData.All(item => item == 0);
|
|
|
|
|
How do you declare item in this case?
|
|
|
|
|
item is an inline-declared parameter. You shouldn't have to explicitly declare it anywhere. Enumerable.All should be able to determine the type of the parameter at compile-time.
Note: I'm not in front of my compiler right now, but it's possible (?) that you may have to explicitly provide the parameter with a type. In that case, I believe the syntax would be:
arrayData.All((int item) => item == 0); (disclaimer: this is all coming from memory, so I might not be spot-on )
|
|
|
|
|
It seems to work fine now
|
|
|
|
|
Your method works fine, but it looks like it is not possible to check if all elements equal 0 in a 2D array. I couldn't find a way to do that for a 2D array as I did for a 1D. Is there a way to check if all elements is 0 in a 2D array?
|
|
|
|
|
Hi all,
I am using ASP.NET 2.0 in C#. I have a database full of products. Depending on the product series depends on the specs that I want to show. I have a gridview to show the different models of a series. Each product series has a different set of specs. I would like to have a gridview to show the specs of a number of models in a series and if you click on a different series you might get a different specs.
Down to it, I want to know how to hide columns that are null or empty when a query is done. And if the query has data in the columns to show them. This way only the columns that have data in them are shown.
Any suggestions?
edcorusa
|
|
|
|
|
string sql = "Select Count(*) From TABLE_NAME";
Run this query and catch return value using ExecuteScalar(). If return value equal 0 so GridView.Datasource = null;
Another way; if using DataSet or DataTable use Row.Count property. If Row.Count equal 0 so GridView.Datasource = null;
|
|
|
|
|
I am sorry, but that does not seem to do what I am after.
Lets say I have three columns, titled COL1, COL2 and COL3. When I do a query and rows of data are return and there is no data in COL3 I wish to hide it.
|
|
|
|
|
DataTable myDt = ....(write necessary code)
DataGridView1.DataSource = SupressEmptyColumns(myDt);
private DataTable SupressEmptyColumns(DataTable dtSource)
{
System.Collections.ArrayList columnsToRemove = new System.Collections.ArrayList();
foreach(DataColumn dc in dtSource.Columns)
{
bool colEmpty = true;
foreach(DataRow dr in dtSource.Rows)
{
if (SqlConvert.ToString(dr[dc.ColumnName]) != string.Empty)
{
colEmpty = false;
}
}
if (colEmpty == true)
{
columnsToRemove.Add(dc.ColumnName);
}
}
foreach(string columnName in columnsToRemove)
{
dtSource.Columns.Remove(columnName);
}
return dtSource;
}
|
|
|
|
|
I have been building a GUI that interfaces with 3 services via remoted interfaces. I'm using GenuineChannels (http://www.genuinechannels.com) broadcast engine as the framework for event based communication between services & the GUI. Since you can only register one remoted object per AppDomain (I hope that statement is correct), I've had to create a seperate AppDomain for each UserControl in the GUI so more than one remoted object can be registered. Each UserControl contains a TreeView that needs to be updated via the broadcast engine, or remoted events. Everything appears to be working just as I had hoped, but here is my problem. I've tried using different types of delegates at different scopes within the code & also tried refactoring my code, but I cannot seem to come up with a way to update the TreeView instance within the UserControl from a remoted object in a seperate AppDomain. Here's most of the code from the classes involved. Unimportant peices have been removed.
namespace Console
{
public partial class ControlDelegate : UserControl
{
public ControlDelegate()
{
InitializeComponent();
// Create appdomainsetup information for the new appdomain.
AppDomainSetup setup = new AppDomainSetup();
setup.ApplicationBase = System.Environment.CurrentDirectory;
setup.ApplicationName = ("Delegate-" + AppDomain.CurrentDomain.FriendlyName);
//Create evidence for new appdomain.
Evidence evidence = AppDomain.CurrentDomain.Evidence;
// Create the application domain.
AppDomain domain = AppDomain.CreateDomain(("Delegate-" + AppDomain.CurrentDomain.FriendlyName), evidence, setup);
DelegateMessenger remote = (DelegateMessenger)domain.CreateInstanceAndUnwrap(Assembly.GetExecutingAssembly().FullName, Assembly.GetCallingAssembly().GetName().Name + ".DelegateMessenger");
Thread thread = new Thread(new ThreadStart(remote.Construct));
thread.Start();
}
/****************************/
this method must be static to refer to it, which is my problem.
/****************************/
public static void tViewDelegateHeartBeat(Objects.Message message, String nickname)
{
System.Console.WriteLine(message.action);
/****************************/
The line below is all that I need to make project functional.
/****************************/
//tViewDelegate.Nodes.Add(message.action + " " + nickname);
}
}
public class DelegateMessenger : MarshalByRefObject, IDelegateMessenger
{
public static String Nickname = "Delegate-" + Assembly.GetExecutingAssembly().GetName().Name;
public static DelegateMessenger Instance = new DelegateMessenger();
public static IDelegateChat iDelegateChat;
public static IDelegateServer iDelegateServer;
public static Object IDelegateChatLock = new Object();
public void Construct()
{
try
{
// Setup remoting with assembly objects as remote object.
IDictionary props = new Hashtable();
props["name"] = "gtcpd";
props["prefix"] = "gtcpd";
props["priority"] = "100";
props["port"] = "0";
GenuineTcpChannel channel = new GenuineTcpChannel(props, null, null);
ChannelServices.RegisterChannel(channel, false);
WellKnownClientTypeEntry remotetype = new WellKnownClientTypeEntry(typeof(SharedChannels.GenuineTcp.GenuineTcpChannel), "gtcpd://127.0.0.1:48886/DelegateMessenger");
RemotingConfiguration.RegisterWellKnownClientType(remotetype);
// Bind client's receiver.
RemotingServices.Marshal(Instance, "DelegateMessenger");
// Subscribe to the chat event.
lock (IDelegateChatLock)
{
iDelegateServer = (IDelegateServer)Activator.GetObject(typeof(IDelegateChat), "gtcpd://127.0.0.1:48886/DelegateServer");
iDelegateChat = iDelegateServer.JoinDialog(Nickname);
}
}
catch (Exception ex)
{
MessageBox.Show(Environment.NewLine + String.Format("Exception: {0}. Stack trace: {1}.", ex.Message, ex.StackTrace));
}
}
public Object ReceiveMessage(Objects.Message message, String nickname)
{
/*****************************/
this works fine if the receiving function is static, but I
need to refer to an instance method to be able to update
the UserControl TreeView (tViewDelegate).
/*****************************/
AppDomain.CurrentDomain.DoCallBack(delegate { ControlDelegate.tViewDelegateHeartBeat(message, nickname); });
/*****************************/
this works if I register only one remoted object within
the GUI AppDomain, which won't work with my current design
since I need to access several remoted objects from other UserControls.
/*****************************/
// http://blogs.msdn.com/csharpfaq/archive/2004/03/17/91685.aspx
/* if (tViewDelegate.IsHandleCreated)
{
try
{
tViewDelegate.Invoke(new tViewDelegateCallback(this.tViewDelegateHeartBeat), new Object[] { message, nickname });
}
catch (Exception ex)
{
MessageBox.Show(Environment.NewLine + String.Format("Exception: {0}. Stack trace: {1}.", ex.Message, ex.StackTrace));
}
}
*/
return null;
}
public override Object InitializeLifetimeService()
{
return null;
}
}
}
I'm hoping someone sees something silly that I'm doing and can point it out. The project is still in its infancy, so I could refactor everything if need be. Any ideas?
modified on Wednesday, March 11, 2009 3:42 PM
|
|
|
|
|
hi,
i created VSTO 2003 addin for outlook inspector. i want to check the attachment when we open any mail item, i want to know how to check and attachment when we open item from inbox.
here is actually what i want..
when we open any inbox item, inspector region opens, if any attachments is present, upon clicking the addin button which is in inspector region i want that attachment to store in specified location. can any one help me in this. i've created addin in inspector region, i need help form this point. please help me.
Thanks.
Arun.
|
|
|
|
|
Could u explain breafly your question?
|
|
|
|
|
Hi!
I'm learning to work with webservice, and now I have a problem..
I'm using this guide:
http://www.exforsys.com/tutorials/asp.net/creating-and-consuming-xml-web-services-with-csharp.html[^]
When I try to compile my console-application, this message appears:
Error 1 The type or namespace name 'Service1' does not exist in the namespace 'MyClient.MyService' (are you missing an assembly reference?) C:\Documents and Settings\Bryan\Mina dokument\Visual Studio 2008\Webbservice\MyClient\MyClient\Program.cs 15 23 MyClient
Error 2 The type or namespace name 'Service1' does not exist in the namespace 'MyClient.MyService' (are you missing an assembly reference?) C:\Documents and Settings\Bryan\Mina dokument\Visual Studio 2008\Webbservice\MyClient\MyClient\Program.cs 15 56 MyClient
The code for the webservice:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml.Linq;
namespace WebServiceExample
{
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[ToolboxItem(false)]
public class Service1 : System.Web.Services.WebService
{
[WebMethod]
public string HelloWorld()
{
return "Hello World";
}
}
}
The code for my console application:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace MyClient
{
class Program
{
[STAThread]
static void Main(string[] args)
{
MyService.Service1 service = new MyService.Service1();
string message = service.HelloWorld();
Console.WriteLine(message);
}
}
}
|
|
|
|
|
In the project for your console application, has a reference been added to your web service?
|
|
|
|
|
Have you created a web reference to the service ?
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
Hmmm, when I'm adding a reference, I right-click on my projectname in the solutionbox and paste the URL of my service. Is that correct or should I do it on a another way?
|
|
|
|