a question in desgining visual inheritance?

  • Thread starter Thread starter Elhanan
  • Start date Start date
E

Elhanan

hi all

i have a question in desgning a form..

the application in question is something a indexing station.

the user in this indexing station views a document in pdf/tiff format
on the right side of the form and enters the index data through various
fields and listboxes on the left side.

now there are many types of stations, the diference between are the
index fields which must be typed (which could be different set of list
boxes and text fields not to mention subforms for selection windows).

at first i was asked to create somethign so dynamic that it could read
from an xml file the layout of the fields and then dispaly them screen,
but no i see this is way too complex
the general layout of this station is this:

right side a document viewer control (which could a webbrowers, but
i'm considering to a special leadtools OCR control), a splitter, in the
middle, on the left buttom an ok, forward/back buttons (for browsing
back and forth between documents), and on the left side the various
fields. at first i thougth i'd create a user control which will contain
all the fields, but then i thought why not use visual inheritance

the superclass form will conaint only the navigation
butons,splitter,viewer and the subform will be in the same assbmely but
each one will be for a different station. then all the user will do is
to load the corrrect form from a selection box in the start.
 
well first off i've never had much luck with it..

my first problem is that exe is also using a dll, this dll has proxy
webservice and other clients

on the base form when on the load event instantiate the classes and all
goes well, when i simply try to inherit the form i get:
and exception occured while to create an instance of 'base form' the
exception was

file or assembly name 'name of dll' were not found.

somtimes i get another excpetion my own exception i generate as if the
inherited form was tryign to use my class in design time (the dll takes
values from app.config, does that change, is it looking in an another
app.config file if i try use the winforms desginer?
 
Just to play the devil's advocate ...

why not your original idea of using an XML file, it's not that difficult to
do.

<form>
<control type="System.Windows.Forms.TextBox" left="50" top="15" width="100"
/>
<control type="System.Windows.Forms.Button" left="160" top="15" width="25">
Press me now
</control>
</form>

.... or something like that
 
sure, but let consider the listboxes and their own datasources, and
what about field and form validation and the buisness rules which may
come along, some of these fields also have subfroms for selection.
and what visual layout, after all with the visual desginer can do thins
much more quickly, here u'll be blind.

i don't see the advantage here.
 
First off ...
=======

If you are publishing a stand alone dll (aka .net assembly), you really do
NOT want it to be relying on a .config file.

app.config is used for APPLICATION configuration, NOT for .dll configuration

Your stand alone assembly should act as a BLACK BOX, which means that you
know what you pass in, you know what to expect out, nothing more, and nothing
less.

Second up
=======

If your .dll requires other .dll files in order to work, when you build your
assembly, these dll files will be copied to your Release/Debug location along
with your assembly output -that is assuming that you have correctly set up
all of the references (which you must have done if you can build your
assembly)

Erm ... I'm not too sure what to say about the rest, I'm not 100% sure I
understand what is going on :

/* **************************************************
* This could be your base Form
************************************************** **/

using System;
using System.ComponentModel;
using System.Windows.Forms;

namespace MyNamespace
{
internal abstract class MyBaseForm : Form
{
private System.ComponentModel.Container components = null;
internal MyBaseForm() { InitializeComponent() }
protected void InitializeComponent()
{
// base form initialisation code
// here you set up your common controls, etc
}
protected override void Dispose( bool disposing )
{
if( disposing ) { if (components != null) { components.Dispose(); } }
base.Dispose( disposing );
}
}
}
/* **************************************************
* This could be your derived Form
************************************************** **/

using System;
using System.ComponentModel;
using System.Windows.Forms;
using MyNamespace;

namespace SomeOtherNamespace
{
public class MyDerivedForm : MyBaseForm
{
public MyDerivedForm() : base()
{
InitializeComponent();
}
protected void InitializeComponent()
{
// derived form initialisation code
// here you set up your rrequired controls, etc
}

}
}
 
Don't misunderstand me, I'm not saying you SHOULD go with the original idea,
however, what you gain from such an approach is the lack of any need to
re-compile should you find you need to add an additional form (maybe a new
station is set up with new indexing requirements).

All of the items you mention can be addressed using this approach so long as
you spend a little time defining your XSD (XMLSchema) ... this is of course
also time that you will spend DESIGNING your Forms inheritance chain ... I
repeat DESIGNING your inheritance chain, NOT coding it! (just in case I
needed to say it).
 
the dll files requiers an activex dll, all my trouble are begning when
i add an inherited form
 
i have no inetntions of lettting go beyond 2 levels, as i understand 3
is the limit for good inheritance.

meanwhile i took out all my application config code from my dll and
placed it in my exe, trasnffered the data to class constructors
(basically it's HTTPclient base class which has to descendent one wraps
a webservice proxy, and the other obtains a url, the base class common
functionaliy is to check to web server, one main, the other a backup,
if one is down, it goes for the other, if other is down as well i
generate an exception)

when i try use the interitented form, i get my own excption as though
all the server are down.
this is the function which checks the server, (could be a secruity
problem when activated in desgin time?)


try
{
if (url.Length==0) throw new Exception("no Server Name");
WebClient w= new WebClient();
w.DownloadData("http://" + url);
return true;
}
catch (WebException e)
{
System.Text.RegularExpressions.Match m=
System.Text.RegularExpressions.Regex.Match(e.Message,@"\d+");
if(m.Success)
{
return true;
}
else
return false;

}
 
well i found part of the problem, as i tought, the desginer took the
appsettings from devenv.config, no my own app.config, so when i coppied
the appSettings to devenv.config file it saw the form. (i know sucks
but i don't know how to prevent this from now happening in desgin time,
i remember user controls have some switch tells them if they are in
design).

let's assume i've passed it. however when i try to rebuild everythign i
get an exception in the desginer of inherited forum
the same one i got the first time:

exception occured while to create an instance of 'base form' the
exception was
file or assembly name 'name of dll' were not found
 
solved it that as well

i'm using this.desgintime in the load event to check if i should act on
it

up untill now all my files were sitting on a novell fileserver, (entire
rebuild process was there as well..)
(can't use VSS on on novell now can i)
when i copied entire solution to my c and deleted all the pdb files (so
they won't reference in debug to files on the server) it worked.
 
You will have to read the contents into a Stream and then use that to
construct your Bitmap ... there's a .ctor that takes a Stream as an arg.
 
well first of all the the designer of the subform executes the load
event of the superform right?

and the load event has calls the app.config files, but when designer
file does it, the calls actually read the devenv.config file, becouse
designer is offcourse part of the devenv.exe

so placing my settings in the conf in the file corrected the situtaion,
which let to another solution, it wasn't the novell problem as i
thought

let look againt, the load event is executed by the designer, what's in
the load even, calls to classes of my dll (not shared), where is my
dll? in the bin directory of MY exe, but's it's not MY exe which uses
the load event, it's devenv, so placing dll where devenv.exe is also
corrected the problem becouse designer found it.

which kind leads to a large problem, it have dump grabage in the devenv
folder
 
yes, but how do i read to cotents? and what are the conents, don't
forget that esstinally the webbrowser only has html in it, i have to
somehow get graphics of the browser and dump them in a stream.
 
I'm really not sure what you want to do

1) If you want to create an image of THE WHOLE page from your browser, you
will have to read it (the page) into a Stream (I think it's a BitStream that
you will actually use), you will have to get hold of this when your browser
receives the page from the web-server.

2) If you want to get the images out of the web page, then you will have to
open the HTML document and manually parse it in order to find <IMG> and
<IMAGE> tags, then you will have to extract the href attribute of those
elements in order to find the URL for the image, then you will have to read
the images into a Stream and use that Stream to create a Bitmap locally.

If scenario one : you have to remember that ALL information on a computer is
a whole bunch of ones and zeros, it only becomes meaningful data when it is
further processed ... therefore whether your browser is displaying HTML, XML,
graphics, or anything else a web browser can display, it is ALL sent accross
the wire in a Stream of some kind. You must intercept that Stream and use it
for your own purposes.

ps. it can be illegal to just take images from the web unless express
permission is granted
 
i have no idea how to get the whole page from the browser

as for scenario 2 i thought about going through the html, but the whole
page is just frames with no html.

anyway i think it's rather pointless now, becouse they agreet to send
me the direct link to documents, so all i'll have to do is to use
webClient.DownloadData, to get the goods (or use openRead and directly
save it to a file right)
and no, no illigel stuff here, becouse don't forget we are simply
talking about an indexing station, which recieve the company's document
after they were scanned for indexing.
what's the fastest way to turn the steam data to a dib? i want to able
to send this to OCR class which can recieve a dib handle
 
//
// NOTE : you will have to keep the stream open for the lifetime of the Bitmap
//
Stream myStream = myWebClient.OpenRead(uriString);
Bitmap myBitmap = new Bitmap(myStream);

//
// Draw the bitmap to a control in your application, such as
System.Windows.Forms.Panel
//
Graphics g = myPanel.GetGraphics();
g.Clear(Color.Transparent);
g.DrawImage(myBitmap, 0, 0);

//
// and don't forget to close the stream
//
myStream.Close();

//
// OR - write the image to file
//
myBitmap.Save(localFileName, ImageFormat.Bmp);
mySttream.Close();

//
// OR -
//

if you do need to display the image in your app AND you need to save it
locally and you're feeling really brave, you could opt for the first option,
and then when your user chooses the format they wish to save the image in,
you retrieve the image from the panel and save.

Good luck :o))
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top