Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Locked thread
SLOSifl
Aug 10, 2002


My window looks like this:
code:
|========================|
||                      ||
||                      ||
||                      ||
||   ---------------    ||
||                      ||
||                      ||
||                      ||
|========================|
Where I have some text represented by "-----------------".

The window has to be much taller than the text to accommodate the rotation. The window itself is transparent. When I drag the window to the edge of the screen, the blank space above the text is forced back onto the screen. For some reason, either Windows or WPF won't let that area extend off the desktop.

edit: The bounds aren't changing.

Adbot
ADBOT LOVES YOU

fankey
Aug 31, 2001

SLOSifl posted:

My window looks like this:

I think the Window manager is yanking your window back into view. Apparently setting Top on the window bypasses this - at least on Vista. Drag the blue area to move the window, click on the orange to rotate the rectangle.

XAML
code:
<Window x:Class="WPFApplication1.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:MyNamespace="clr-namespace:WPFApplication1"
    Title="Window1" 
    SizeToContent="WidthAndHeight" 
    WindowStyle="None"
    AllowsTransparency="True"
    Background="Transparent">
    <Grid Background="Transparent">
    <Rectangle Fill="Blue" Stroke="Yellow" Width="180" Height="40" Margin="150">
    </Rectangle>
      <Rectangle Fill="Orange" Stroke="Green" Width="160" Height="20" Margin="160">
      <Rectangle.Triggers>
        <EventTrigger RoutedEvent="Rectangle.MouseDown">
          <BeginStoryboard>
            <Storyboard>
              <DoubleAnimation From="0" To="360" Duration="0:0:1" 
                Storyboard.TargetProperty="RenderTransform.Angle" />
            </Storyboard>
          </BeginStoryboard>
        </EventTrigger>
      </Rectangle.Triggers>
      <Rectangle.RenderTransform>
        <RotateTransform x:Name="Rotation" Angle="0" CenterX="80" CenterY="10" />
      </Rectangle.RenderTransform>
    </Rectangle>
  </Grid>
</Window>
C#
code:
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Shapes;
using System.Windows.Media;

namespace WPFApplication1
{
  /// <summary>
  /// Interaction logic for Window1.xaml
  /// </summary>

  public partial class Window1 : Window
  {
    public Window1()
    {
      InitializeComponent();
    }
    bool dragging = false;
    Point start;
    protected override void OnMouseDown(MouseButtonEventArgs e)
    {
      dragging = true;
      start = e.GetPosition(null);
      CaptureMouse();
      base.OnMouseDown(e);
    }
    protected override void OnMouseMove(MouseEventArgs e)
    {
      if (dragging)
      {
        Point pt = e.GetPosition(null);
        Top = Top + pt.Y - start.Y;
        Left = Left + pt.X - start.X;
      }
      base.OnMouseMove(e);
    }
    protected override void OnMouseUp(MouseButtonEventArgs e)
    {
      dragging = false;
      ReleaseMouseCapture();
      base.OnMouseUp(e);
    }
  }
}

Dromio
Oct 16, 2002
Sleeper
Any ideas on how to remove an event handler that was defined as an anonymous function?
code:
nClient.LogMessage += delegate(object sender, LogMessageEventArgs args)
   {
   args.Message = "Created " + LockName + " lock file.";
   };
nClient.Import(TempFile, RepoPath + "/Locks/" + LockName, Recurse.None);
//I need to remove the event handler here.
I saw a page that suggested setting the eventhandler to null, but that gives a compiler error. Is there a simple way to do it?

csammis
Aug 26, 2003

Mental Institution

Dromio posted:

Any ideas on how to remove an event handler that was defined as an anonymous function?
code:
nClient.LogMessage += delegate(object sender, LogMessageEventArgs args)
   {
   args.Message = "Created " + LockName + " lock file.";
   };
nClient.Import(TempFile, RepoPath + "/Locks/" + LockName, Recurse.None);
//I need to remove the event handler here.
I saw a page that suggested setting the eventhandler to null, but that gives a compiler error. Is there a simple way to do it?
You need a reference to the handler method:
code:
LogMessageEventHandler handler = delegate {...};
nClient.LogMessage += handler;
nClient.LogMessage -= handler;
And at that point you should evaluate whether or not to just make it its own method.

Dromio
Oct 16, 2002
Sleeper

csammis posted:

You need a reference to the handler method:
And at that point you should evaluate whether or not to just make it its own method.
I was afraid of that. I really liked the in-line syntax, but I guess it just won't work for me here.

Ethangar
Oct 8, 2002

The .NET thread seems like a good place to ask this: I need a T-SQL book. I've never really had much experience with T-SQL. I did a lot of Oracle PL/SQL back in school, but now I'm really out of touch with database work of any type. Looking at a new job that uses T-SQL in an application environment. I'm educated with stored procedures and database theory, but am quite rusty and need a refresher specific to T-SQL. With that in mind, what do you people using it recommend for a book.

dwazegek
Feb 11, 2005

WE CAN USE THIS :byodood:
Doesn't anyone have an answer for this question? Is there a valid reason to design stuff this way, or is it just a case of overusing asynchronous methods?

dwazegek posted:

I came upon a piece of code which was something like this:
code:
public void OpenConnection()
{
    Thread t = new Thread(new ThreadStart(Start));
    //no sure about this, could also be that a thread was grabbed from 
    //the thread pool.
}

private void Start()
{
    // do some stuff and create a HttpWebReqeust

    request.BeginGetResponse(new AsyncCallback(ResponseCallback), state);
}

private void ResponseCallback(IAsyncResult result)
{
    //do some more stuff and prepare to read from the stream
    
    stream.BeginRead(bytes, 0, bytes.Length, new AsyncCallback(ReadCallback), state);
}

private void ReadCallback(IAsyncResult result)
{
    int read = stream.EndRead(result);
    if (read > 0)
    {
        //process read data

        stream.BeginRead(bytes, 0, bytes.Length, new AsyncCallback(ReadCallback), state);
    }
    else
    {
        //do close stuff
    }
}
Is there any reason to do stuff like that? After OpenConnection, the entire process is run in a seperate thread, so it's not blocking anything else anyway, so why make everything asynchronous?

edit: Just to make it clear; the asynchronous method calls where always near, or at the end of the method, so the thread in which the code was being executed would exit pretty much immediately.

SLOSifl
Aug 10, 2002


dwazegek posted:

Doesn't anyone have an answer for this question? Is there a valid reason to design stuff this way, or is it just a case of overusing asynchronous methods?
Just because the calls were at the end of the method doesn't mean anything. It depends on how long the request takes. Otherwise, the method would be blocked from exiting until the response was received.

Can there be multiple requests running at once? Does the thread that's created have stuff to do other than wait for responses?

I see nothing in your example that indicates asynchronous calls are a bad idea.

dwazegek
Feb 11, 2005

WE CAN USE THIS :byodood:

SLOSifl posted:

Just because the calls were at the end of the method doesn't mean anything. It depends on how long the request takes. Otherwise, the method would be blocked from exiting until the response was received.

Can there be multiple requests running at once? Does the thread that's created have stuff to do other than wait for responses?

I see nothing in your example that indicates asynchronous calls are a bad idea.

Yes, there are multiple requests running at once. Each request connects to a source over a HTTP connection and starts reading data which it processes.

The thread that's created in OpenConnection only creates the HttpWebRequest and then calls BeginGetResponse. Calling BeginGetResponse is literally the last thing it does, after that it ends.

This is the case with each method, a tread starts, does something, and then moves the rest of the work to a different thread and immediately exits. Why not keep each request's work in one thread?

In other words:
code:
public void OpenConnection()
{
    Thread t = new Thread(new ThreadStart(Start));
    t.Start();
    //no sure about this, could also be that a thread was grabbed from 
    //the thread pool.
}

private void Start()
{
    // do some stuff and create a HttpWebReqeust
    WebResponse response = request.GetResponse();
    while(stuff is being sent)
    {
        response.Read(bytes, 0, bytes.Length);
        ProcessData(bytes);
    }
    //close stuff
}
In case it wasn't clear; I forgot to add a t.Start() at the end of OpenConnection.

Hey!
Feb 27, 2001

MORE MONEY = BETTER THAN
Say I have a GridView that's binding to a list of items, and each row in the GridView has a Repeater that's binding to a list of items. (This is just hypothetical, they could be two Repeaters or whatever.)

code:
<asp:GridView runat="server" DataSource='<%# MyArray%>'>
    <asp:Repeater runat="server" DataSource='<%# SomeOtherArray %>'>
    </asp:Repeater>
</asp:GridView>
How can an item in the Repeater get a handle on the DataItem that the GridView is currently binding? Like if a control inside the Repeater wanted to see which item the Repeater was currently binding to, it could just call Container.DataItem. But I don't see a way of chaining the Container property to go "up a level" to see the GridView's current DataItem.

Hey! fucked around with this message at 22:10 on Aug 7, 2007

ribena
Nov 24, 2004

Hag.
Jesus. For some unknown reason all of the forms in one of my projects have stopped working; they all come up like this:



I found this site (German) which seems to describe the same problem if my German lessons from a few years ago are serving me correctly. I tried messing around with those two lines all I could, but to no avail. Copying the files into a new project didn't fix it either, which leads me to believe that it's something in the source. Help please!

Nurbs
Aug 31, 2001

Three fries short of a happy meal...Whacko!

ribena posted:

Jesus. For some unknown reason all of the forms in one of my projects have stopped working; they all come up like this:



I found this site (German) which seems to describe the same problem if my German lessons from a few years ago are serving me correctly. I tried messing around with those two lines all I could, but to no avail. Copying the files into a new project didn't fix it either, which leads me to believe that it's something in the source. Help please!

Something like that happened to me. I never found a solution though, just pulled the form out of a backup and added it to the project.

I'm curious if anyone knows if there is anything like ListBox.IndexFromPoint() function for datagridviews.

I have a datagridview which has a comboboxcells in it. I would like for the user to be able to right click on a cell, and then a form for that particular option will popup and auto fill based on the value of that cell (and then the user can edit it as they please). I figure I can code something together to get the index pretty easily but I don't want to reinvent the wheel if its already hidden somewhere.

poopiehead
Oct 6, 2004

dwazegek posted:

This is the case with each method, a tread starts, does something, and then moves the rest of the work to a different thread and immediately exits. Why not keep each request's work in one thread?

Maybe because of the overhead of multithreading? Your code would cause threads to be open, holding resources for a much longer time than the first example.

ribena
Nov 24, 2004

Hag.

ribena posted:

Jesus. For some unknown reason all of the forms in one of my projects have stopped working; they all come up like this:



I found this site (German) which seems to describe the same problem if my German lessons from a few years ago are serving me correctly. I tried messing around with those two lines all I could, but to no avail. Copying the files into a new project didn't fix it either, which leads me to believe that it's something in the source. Help please!

Answering my own question. Yes, I'm an idiot. I had done a global find&replace for Initialize->Initialise. This obviously affected InitializeComponent(), causing these symptoms. What a tool. :(

dwazegek
Feb 11, 2005

WE CAN USE THIS :byodood:

poopiehead posted:

Maybe because of the overhead of multithreading? Your code would cause threads to be open, holding resources for a much longer time than the first example.
Could be, but I thought calling asynchronous methods by using a callback spawned another thread, so even though the source thread wouldn't be open as long as in my code, it would just keep another thread open instead.

And wouldn't the overhead from constantly opening new threads be much more costly than the alternative?

The "worst" section by far is the section in which the stream is read, the buffer that is used is pretty small (although that can be changed easily enough), and the amount of data that is being sent is quite a lot in most cases, so it's not unthinkable that it would be using thousands of new threads. In the most extreme cases we have, it would be switching threads approximately a thousand times each second per source, and it's not uncommon to have 16 or so sources connected at once.

Goon Matchmaker
Oct 23, 2003

I play too much EVE-Online
I'm having a bit of a :psyduck: moment trying to understand the reason why I'm having to do this:

code:
PointF myStartPoint =
                    new PointF((float)(double)r["FromX"], (float)(double)r["FromY"]);
It's my understanding that DataTables are strongly typed and thus I should only have to do one cast, the float cast. But if I remove the cast to double I get an InvalidCastException. Can anyone explain why I'm having to do this double cast to get this piece of code to work properly?

Fiend
Dec 2, 2001

Safrax posted:

I'm having a bit of a :psyduck: moment trying to understand the reason why I'm having to do this:

code:
PointF myStartPoint =
                    new PointF((float)(double)r["FromX"], (float)(double)r["FromY"]);
It's my understanding that DataTables are strongly typed and thus I should only have to do one cast, the float cast. But if I remove the cast to double I get an InvalidCastException. Can anyone explain why I'm having to do this double cast to get this piece of code to work properly?
Can the object not be cast directly from it's datatype to a float? What is "r[FromX]"? An object, a string, a what?

Goon Matchmaker
Oct 23, 2003

I play too much EVE-Online

Fiend posted:

Can the object not be cast directly from it's datatype to a float? What is "r[FromX]"? An object, a string, a what?
In the database that column is a float, which I believe comes over in the DataTable as double but has to be cast to whatever it actually is before using it.

biznatchio
Mar 31, 2001


Buglord

Safrax posted:

In the database that column is a float, which I believe comes over in the DataTable as double but has to be cast to whatever it actually is before using it.

Without checking to see how accurate this statement is: I believe when you're unboxing a value (taking a value of type "object" and casting it to a value type), you have to unbox it to exactly the same type that was boxed. Then, you can use an explicit cast to get it to another type.

You could just do this instead:

code:
PointF myStartPoint =
                    new PointF(Convert.ToSingle(r["FromX"]), Convert.ToSingle(r["FromY"]));

Magicmat
Aug 14, 2000

I've got the worst fucking attorneys
Are there any Win Forms wonks out there that would let me bounce ideas off them via AIM, e-mail or PMs? I'm about ready to go postal on my copy of VS because I can't make my form perform a relatively simple action. When I post in this thread and elsewhere, my question floats off into the wild blue unanswered, possibly because I suck at explaining what I want to do succinctly, or possibly because what I want is just unique enough that there's no pre-canned answer. Being able to talk to someone who can ask for clarifications, ask me questions, and generally be interactive would help me out immensely.

Any takers? Pretty please?

csammis
Aug 26, 2003

Mental Institution
This entire thread isn't pre-canned answers, and if you suck at explaining yourself, it won't get better over AIM or email. What's the problem?

Magicmat
Aug 14, 2000

I've got the worst fucking attorneys

csammis posted:

This entire thread isn't pre-canned answers, and if you suck at explaining yourself, it won't get better over AIM or email. What's the problem?
Well, in a one-on-one setting, the person could ask me to clarify certain parts that may not make sense, ask further questions of me, or just provide them with more information on whatever they needed. Here in the thread, people just seem to skip questions that aren't clear (and I can't, frankly, blame them.)

Just generally, you can't be ignored in a one-on-one setting. At the very least, the other person will respond with "I don't know" or at least a vague answer, which is infinitely more reassuring when you're trying to learn than no answer at all. Plus, the lag time for small questions can hinder momentum; if I just want to know what property to use to do X when I'm in full-on work mode, it's much easier to just ping someone on AIM then to stop what I'm doing and wait a day or two for an answer on here or another forum. Plus, having a mentor, of sorts, is always helpful. Even with this useful thread, having someone who knows your previous work and where you are as a coder, and can provide advice based on that, is incredibly helpful.

So I'm not at all impugning the quality of this thread or the people in it, but merely suggesting that one-on-one help is often more useful than a free-for-all, especially when one has an ongoing need for related help, as I do.

As for my specific question, I posted it a few pages back and got no response (ditto with a few preceeding questions I posted earlier,) but here's a link to my post on the MSDN forums, which is a bit more up to date.

csammis
Aug 26, 2003

Mental Institution

Magicmat posted:

As for my specific question, I posted it a few pages back and got no response (ditto with a few preceeding questions I posted earlier,) but here's a link to my post on the MSDN forums, which is a bit more up to date.

Well first of all, it sounds like your application is going to be a usability clusterfuck based on the number of TableLayoutPanels you're using (more than one). If you can't describe it succinctly, and you start running into these sorts of problems, it may be time to start redesigning your solution. Draw a picture of what you have and post it.

If you don't need the outer table layout, try setting the Dock property on the ListView to Bottom and put the dynamic TableLayoutPanel in a scrollable Panel with Dock.Fill on it.

Nurbs
Aug 31, 2001

Three fries short of a happy meal...Whacko!

Magicmat posted:

words

You might want to consider using http://www.codeproject.com/cs/miscctrl/TgXPPanel.asp instead of hacking a regular control to do the expanding / collapsing. It will add scroll bars automatically. You can also resize it programatically easily enough. I've been using it with a datagridview inside and resizing it to fit the datagridview (which can have rows added/deleted or initialized with X # of rows)

genki
Nov 12, 2003

Magicmat posted:

Well, in a one-on-one setting, the person could ask me to clarify certain parts that may not make sense, ask further questions of me, or just provide them with more information on whatever they needed. Here in the thread, people just seem to skip questions that aren't clear (and I can't, frankly, blame them.)

Just generally, you can't be ignored in a one-on-one setting. At the very least, the other person will respond with "I don't know" or at least a vague answer, which is infinitely more reassuring when you're trying to learn than no answer at all. Plus, the lag time for small questions can hinder momentum; if I just want to know what property to use to do X when I'm in full-on work mode, it's much easier to just ping someone on AIM then to stop what I'm doing and wait a day or two for an answer on here or another forum. Plus, having a mentor, of sorts, is always helpful. Even with this useful thread, having someone who knows your previous work and where you are as a coder, and can provide advice based on that, is incredibly helpful.

So I'm not at all impugning the quality of this thread or the people in it, but merely suggesting that one-on-one help is often more useful than a free-for-all, especially when one has an ongoing need for related help, as I do.

As for my specific question, I posted it a few pages back and got no response (ditto with a few preceeding questions I posted earlier,) but here's a link to my post on the MSDN forums, which is a bit more up to date.
Based on your description in the forum, I'd say the issue is that the bottom row of the containing TableLayoutPanel doesn't have scrollbars for its content. I think that when you first populate, the control contained in that row doesn't know that it's bigger than the screen because the row is initialized to its default size then expands to fit the control. When you do the resize, the bottom row is forced to fit the viewable area and then the minsize kicks in.

At least, that's my guess. Not sure on how to fix that, but maybe it's something to look into at least.

Mindbullets
Jan 18, 2007
Yea! Getsome!
I must know how you pass a file to a c# program.
What im trying to do is set firefox to use the program by default for certain applications then automatically open it and do whatever.

You know how you open music with a certain program say itunes or realplayer you could click the file and go to Open With then the program and it starts playing. Well id like an explanation of how that works.

Think of it as a php post method.

wwb
Aug 17, 2004

In windows, you get passed a file as the first command line argument. So, passing a file to word would be "winword c:\path\to\mydoc.doc". So, just check the args[0] in the Main routine and you should be all set.

Dromio
Oct 16, 2002
Sleeper
This single thread seems more helpful than entire bulletin boards on the subject.

Now I'm trying to add a custom web control to a page dynamically when a user has clicked a link. The code runs fine, but the control does not appear:
code:
protected void AddCustom_Click(object sender, EventArgs e)
    {
        Control ContainerControl = this.Page.Master.FindControl("contents");
        SpecialControls_Custom NewCustom = new SpecialControls_Custom();
        ContainerControl.Controls.Add(NewCustom);
    }
However, this does work:
code:
protected void AddCustom_Click(object sender, EventArgs e)
    {
        Control ContainerControl = this.Page.Master.FindControl("contents");
        Panel NewPanel = new Panel();
        Button TestButton = new Button();
        TestButton.Text = "Blah";
        NewPanel.Controls.Add(TestButton);
        ContainerControl.Controls.Add(NewPanel);
     }
So it appears that my custom control (which is currently just a panel and some textboxes) is missing something critical that makes it visible. Can anyone guess what it is?

salithus
Nov 18, 2005

Dromio posted:

This single thread seems more helpful than entire bulletin boards on the subject.

Now I'm trying to add a custom web control to a page dynamically when a user has clicked a link. The code runs fine, but the control does not appear:
code:
protected void AddCustom_Click(object sender, EventArgs e)
    {
        Control ContainerControl = this.Page.Master.FindControl("contents");
        SpecialControls_Custom NewCustom = new SpecialControls_Custom();
        ContainerControl.Controls.Add(NewCustom);
    }
However, this does work:
code:
protected void AddCustom_Click(object sender, EventArgs e)
    {
        Control ContainerControl = this.Page.Master.FindControl("contents");
        Panel NewPanel = new Panel();
        Button TestButton = new Button();
        TestButton.Text = "Blah";
        NewPanel.Controls.Add(TestButton);
        ContainerControl.Controls.Add(NewPanel);
     }
So it appears that my custom control (which is currently just a panel and some textboxes) is missing something critical that makes it visible. Can anyone guess what it is?

Does your custom control's constructor set .Visible = true? If not, that may be it.

Dromio
Oct 16, 2002
Sleeper

salithus posted:

Does your custom control's constructor set .Visible = true? If not, that may be it.
Yes. Here's the latest test control:
code:
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="Custom.ascx.cs" Inherits="SpecialControls_Custom" %>

<asp:Panel ID="CustomPanel" runat="server" CssClass="CustomPanel" style="">
    <asp:Panel ID="CaptionPanel" CssClass="CustomCaption" runat="server">
        <asp:Label ID="Caption" runat="server">My Control</asp:Label>
    </asp:Panel>
    <asp:TextBox ID="CustomBox" TextMode="MultiLine" runat="server" Text=""></asp:TextBox>
    <asp:Button ID="SaveButton" runat="server" Text="Save" OnClientClick="SubmitCustomScript(this)" UseSubmitBehavior="false" />
</asp:Panel>
And the code-behind:
code:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class SpecialControls_Custom : System.Web.UI.UserControl
{
    public SpecialControls_Custom()
    {
        this.Visible = true;
    }
    
    protected void Page_Load(object sender, EventArgs e)
    {
        this.Visible = true;
    }
}

uXs
May 3, 2005

Mark it zero!
I have a gridview on a (fairly complicated) aspx page. In the HTML code that it spits out, a starting "div" tag is automatically generated right before the "table" tag. However, a matching closing "div" tag is not generated. Anyone have any idea what can be wrong here ? The missing tag is creating at least one problem and I'm guessing that it could be the cause of another one.

Edit: Never mind, found it. See this link for more details. Problem was using SetRenderMethodDelegate to render a gridview with multiple (merged) headers and having an error in the code to do it. Doing the change in the linked comment fixed it. (I'm using the simplified version by Mykola Tarasyuk linked to in another comment there btw.)

uXs fucked around with this message at 15:56 on Aug 13, 2007

wwb
Aug 17, 2004

Dromio posted:

This single thread seems more helpful than entire bulletin boards on the subject.

Now I'm trying to add a custom web control to a page dynamically when a user has clicked a link. The code runs fine, but the control does not appear:
code:
protected void AddCustom_Click(object sender, EventArgs e)
    {
        Control ContainerControl = this.Page.Master.FindControl("contents");
        SpecialControls_Custom NewCustom = new SpecialControls_Custom();
        ContainerControl.Controls.Add(NewCustom);
    }
However, this does work:
code:
protected void AddCustom_Click(object sender, EventArgs e)
    {
        Control ContainerControl = this.Page.Master.FindControl("contents");
        Panel NewPanel = new Panel();
        Button TestButton = new Button();
        TestButton.Text = "Blah";
        NewPanel.Controls.Add(TestButton);
        ContainerControl.Controls.Add(NewPanel);
     }
So it appears that my custom control (which is currently just a panel and some textboxes) is missing something critical that makes it visible. Can anyone guess what it is?

You need to also recreate said control OnInit for things to work right. A much easier way to do this in general is to have the control exist and set it's visible property to false until you need it.

Dromio
Oct 16, 2002
Sleeper

wwb posted:

You need to also recreate said control OnInit for things to work right. A much easier way to do this in general is to have the control exist and set it's visible property to false until you need it.

I may need multiple instances of the control on the same page -- that's one reason I'm dynamically adding them to the page.

It looks like the life-cycle of the control is getting in the way or something. Are you saying I'd have to create my control's child controls in my OnInit() function, not declaring them in the ascx?

salithus
Nov 18, 2005

Dromio posted:

I may need multiple instances of the control on the same page -- that's one reason I'm dynamically adding them to the page.

It looks like the life-cycle of the control is getting in the way or something. Are you saying I'd have to create my control's child controls in my OnInit() function, not declaring them in the ascx?

What about creating a collection of them in OnInit, then add and place them in ascx. Will that work?

wwb
Aug 17, 2004

If you need 0 or more, just use a repeater to contain them.

Mecha
Dec 20, 2003

「チェンジ ゲッタ-1! スイッチ オン!」
Is there some voodoo to handling drag-n-drop that I'm not seeing? I've tried setting virtually every control in my main form(and even the form itself for grins) to allow drops, and tried handling _DragEnter and _DragDrop in several controls, but none of them ever change the cursor nor allow the drop. I've looked through several tutorials which all say that this should be all you need, but for some reason it won't work at all. :(

rckgrdn
Apr 26, 2002

So that's how it's made...

Dromio posted:

This single thread seems more helpful than entire bulletin boards on the subject.

Now I'm trying to add a custom web control to a page dynamically when a user has clicked a link. The code runs fine, but the control does not appear:
code:
protected void AddCustom_Click(object sender, EventArgs e)
    {
        Control ContainerControl = this.Page.Master.FindControl("contents");
        SpecialControls_Custom NewCustom = new SpecialControls_Custom();
        ContainerControl.Controls.Add(NewCustom);
    }
Try this:
code:
protected void AddCustom_Click(object sender, EventArgs e)
    {
        Control ContainerControl = this.Page.Master.FindControl("contents");
        SpecialControls_Custom NewCustom = (SpecialControls_Custom)this.LoadControl("relative/path/to/yourcontrol.ascx");
        ContainerControl.Controls.Add(NewCustom);
    }
The main gist of the problem you're having is the distinction between custom controls and web usercontrols. Custom controls have everything in code to render their contents, so can be initiated with the plain old constructor, while web usercontrols use the ASCX file to define the contents. When you did 'new SpecialControls_Custom();' all you did was instantiate an instance of the class behind the web usercontrol - without it's corresponding ASCX it does nothing, as you found out.

I've probably not done a great job of explaining this, but I'm taking a quick break from a hellishly busy day so please forgive any mistakes!

Dromio
Oct 16, 2002
Sleeper

quote:

I've probably not done a great job of explaining this, but I'm taking a quick break from a hellishly busy day so please forgive any mistakes!
Actually, you hit on the distinction between custom controls and web usercontrols that I had never seen. And of course the terms are all so generic that it's hard to search them out. I believe this is just what I needed, thank you.

dwazegek
Feb 11, 2005

WE CAN USE THIS :byodood:

Mecha posted:

Is there some voodoo to handling drag-n-drop that I'm not seeing? I've tried setting virtually every control in my main form(and even the form itself for grins) to allow drops, and tried handling _DragEnter and _DragDrop in several controls, but none of them ever change the cursor nor allow the drop. I've looked through several tutorials which all say that this should be all you need, but for some reason it won't work at all. :(

Are you setting the DragEventArgs.Effect property in the DragEnter event method to the proper setting? Try DragDropEffects.All (I have to admit, I don't know what the other effects do).

Adbot
ADBOT LOVES YOU

Fastbreak
Jul 4, 2002
Don't worry, I had ten bucks.

Inquisitus posted:

Bunch of stuff on the window stuff.

Awesome, thanks for giving me direction. You wouldn't happen to want to just toss me the function you wrote to get all that would you and save a brother a whole bunch of time? :)

  • Locked thread