save dynamically added textboxes in runtime in c# how? - datagridviewtextboxcell

How can I save dynamically added textboxes in the project in runtime?
I add textboxes like that and I want to save them into my project.
int x = 10;
int y = 20;
for (int i = 1; i <= 5; i++)
{
TextBox a = new TextBox();
a.Location = new Point(x, y);
y += 30;
a.Name = "1";
a.Text = "2";
this.Controls.Add(a);
}

I don't know that you can save them in your 'project' per-se, but you could serialize the dynamic information to any type of data-storage (XML, database, etc.) and initialize your application with that information each time it starts. Sorry if that doesn't answer your question.

Related

How to plot a histogram with strings in anylogic

i have an array with some random sequence
for example : long[] X = {23,1,4,2,.............,4,2,1,3,..........};
in data base i have the names for each numbers(names in the image)
i want to plot a histogram for (23,4);(1,2);(4,2);(2,3)............from the sequence in X[].
but I need something like this
I am not sure how to do it, as the data set only allows the type double, how can I add strings.
long[] X = Disassemblysequence.getDisassemblySequence(); //random sequence
String[] Components = f_Components(); //list of Components from data base
for(int i = 0; i<C; i++){
String A = Components[(int)(X[i] -1)];
double EOL = (double)X[i+C];
String Status = "";
//double Com = (double) X[i];
//double S = (double) X[i+C];
if (EOL == 0){
Status = "Not Removed";
}
else if(EOL == 2){
Status = "Reuse";
}
else if(EOL == 3){
Status = "Remanufacture";
}
else if(EOL == 4){
Status = "Recycle";
}
d_Components.add(A,EOL);
}
It appears that you don't want a histogram per see, since a histogram will calculate some of the values for you, which you already have calculated. Rather you simply need to display them in a bar chart.
You can add bars to a bar chart using standard code see example below
And here is the output
If you want to have custom x-axis labels you need to not show the legend and create your own - but this can be a separate question

Updating z-values for ILNumerics ILSurface

I'm a new ILNumerics Visualization Engine user and I'm still coming up to speed on how to use it well. I've searched extensively for how to update the z-values of an ILSurface and read the posts, but I'm still not clear on how to do this.
I'm able to generate a surface and set up a camera to view it (Hamyo Kutschbach told me that's the best way to ensure that the aspect ratios of the surface don't change when rotating the surface, which is important in my application). Here's the code that displays a sin(x)/x function:
// Generate the data
ILArray<double> z = SincFunc(rows, cols, 10, 50);
ILArray<double> x = new double[cols];
ILArray<double> y = new double[rows];
for (int i = 0; i < cols; i++)
x[i] = (double)i;
for (int i = 0; i < rows; i++)
y[i] = (double)i;
// create the scene
scene = new ILScene();
pointCloudSurface = new ILSurface(z, x, y)
{
Colormap = Colormaps.Jet,
UseLighting = true,
Wireframe = { Visible = false },
Children = { new ILColorbar()
{
Height = 0.5f,
Location = new PointF(0.95f, 0.05f),
Children = { new ILLabel("microns") { Position = new Vector3(0.5,1,0), Anchor = new PointF(0.5f,0) } } }
},
Alpha = 1.0f
};
// Configure the surface and display it
scene.Camera.Add(pointCloudSurface);
scene.Camera.Position = new Vector3(50, 50, 700);
scene.Camera.LookAt = new Vector3(50, 50, 0);
scene.Camera.Top = new Vector3(0, 0, 700);
scene.Camera.Projection = Projection.Perspective;
scene.Camera.ZNear = 1.0f;
scene.Camera.ZFar = 0.0f;
scene.Camera.Top = new Vector3(1, 0, 0);
// Turn off the Powered by ILNumerics label
scene.Screen.First<ILLabel>().Visible = false;
ilPanel1.Scene = scene;
ilPanel1.Configure();
ilPanel1.Refresh();
And it works well. So now I want to change the z-values and update the plot without closing ilPanel1 because this plot is embedded in a Windows Form. Advice would be appreciated! Hopefully other newbies will find this post useful as well.
After further rummaging around, I came across a method, UpdateColormapped(), that does the trick. It's placed near the end of the code above like this:
scene.Camera.First<ILSurface>().UpdateColormapped(z);
ilPanel1.Scene = scene;
ilPanel1.Configure();
ilPanel1.Refresh();
It can be found in the API documentation here: UpdateColormapped()
It can also change the x and y data and perform other mods, but it requires that the z data be a float array, so if you're working double precision, you'll have to take the appropriate steps to get it into a float array.

JavaFX8 Timeline to scroll Grid of Circle Objects?

Using JavaFX8 and JDK 1.8.0_74 in IntelliJ, I created a basic pixel editor app. I have two windows(stages). One is a 32x128 matrix of Circle Objects placed in a Grid Pane and the other, a Tools widow; I have one Controller.java. Using the mouse, the Tools window provides tools to draw lines, rectangles, etc. and a menu for Setup, Files and Playlists. The Files menu presents the user with Open, SaveAs and Delete. To view a saved pixel art file, the user clicks Open and via the FileChooser, the selected file is opened and each Circle’s color property is displayed. The saved pixel art File can be sent via Wi-Fi to an RGB LED matrix that’s also 32x128.
To view pics and video go to: https://virtualartsite.wordpress.com/
I can scroll a displayed pixel art file left, right, up or dow using Timeline. However, I would also like to wrap the pixel image but have failed to eliminate small anomalies that appear at the beginning of the wrap while the remaining 95% of the wrap is correct?
The critical code for class WrapLeft is as follows:
public static void runAnimation() {
timeline = new Timeline(
new KeyFrame(Duration.millis(200), event -> {
wrapFileLeft(pixelArray);
}));
timeline.setCycleCount(100);
timeline.play();
}
public static void wrapFileLeft(Circle[][] pixelArray){
// save pixelArray[r][0] in pixelArrayTmp[r][0] and wrap to end, pixelArray[r][col-1]
Circle[] pixelArrayTmp = new Circle[row];
for (int r = 0; r < row; r++) {
pixelArrayTmp[r] = pixelArray[r][0];
}
// move all the pixelArray columns one column to the left
for (int c = 0; c < col-1; c++) {
for (int r = 0; r < row; r++) {
Color color = (Color) pixelArray[r][c+1].getFill();
pixelArray[r][c].setFill(color);
}
}
// move the pixelArrayTmp[r][0] column into the new, blank, end column of pixelArray[r][col-1]
for (int r = 0; r < row; r++) {
Color color = (Color) pixelArrayTmp[r].getFill();
pixelArray[r][col-1].setFill(color);
} } }
The logic is to temporarily save column 0, shift all the remaining columns to the left one position and replace column 127 with column 0. This is all done in one CycleCount(). The anomalies occur in the first four shifts left; the Circle Objects with colors other than black get changed to an adjacent color. But after four shifts, all remaining shifts appear to be correct?
My best guess is the logical order of execution gets out of order because I not using Timeline properly or trying to execute too much in a single KeyFrame? Increasing the duration doesn’t seem to affect the anomalies.
Thanks for your help.
Logically, your solution is wrong, you are storing referencing to circles in a temporary array, then changing the fill of the referenced circles, then using the updated referenced fill to set the new fill.
Instead of storing references to circles, store the fill values themselves.
public void wrapItLeft(Circle[][] pixelArray){
// save pixelArray[r][0] in pixelArrayTmp[r][0] and wrap to end, pixelArray[r][col-1]
Paint[] pixelArrayTmp = new Paint[N_ROWS];
for (int r = 0; r < N_ROWS; r++) {
pixelArrayTmp[r] = pixelArray[r][0].getFill();
}
// move all the pixelArray columns one column to the left
for (int c = 0; c < N_COLS-1; c++) {
for (int r = 0; r < N_ROWS; r++) {
Color color = (Color) pixelArray[r][c+1].getFill();
pixelArray[r][c].setFill(color);
}
}
// move the pixelArrayTmp[r][0] column into the new, blank, end column of pixelArray[r][col-1]
for (int r = 0; r < N_ROWS; r++) {
pixelArray[r][N_COLS-1].setFill(pixelArrayTmp[r]);
}
}

dragStart starts in the wrong position

I'm implementing the drag and drop in Libgdx with DragAndDrop class.
The actors that i have to move are in a grid (Table), centered in the screen.
The drag and drop starts if i click on the top-right corner of the screen, and not if i click on the actor itself! I can't figure out where is the problem.
This grid is a matrix:
for(int i = 0; i < Constants.ROWS; i++) {
for(int j = 0; j < Constants.COLS; j++) {
slots[i][j] = new Slot(Item.EMPTY, i, j);
}
}
Then i use the code above to create the table:
public class SlotsAreaActor extends Table {
public SlotsAreaActor(SlotsArea slotsArea, DragAndDrop dnd) {
// set the position of this actor in the screen
setPosition(Constants.SLOTS_AREA_ACTOR_X, Constants.SLOTS_AREA_ACTOR_Y);
// spaces all the row and the columns
defaults().space(Constants.ROWS_SPACE);
row().fill().expandX();
Slot[][] slots = slotsArea.getSlots();
for(int i = 0; i < slots.length; i++) {
for(int j = 0; j < slots[0].length; j++) {
SlotActor slotActor = new SlotActor(slots[i][j]);
dnd.addSource(new SlotSource(slotActor));
dnd.addTarget(new SlotTarget(slotActor));
add(slotActor);
}
row();
}
}
}
In the SlotActor class i set the bounds:
x = Constants.APP_WIDTH - Constants.ORIZONTAL_OFFSET - (Constants.TILE_SIZE * (Constants.COLS - slot.getX()));
y = Constants.APP_HEIGHT - Constants.VERTICAL_OFFSET - (Constants.TILE_SIZE * (Constants.ROWS - slot.getY()));
setBounds(x, y, Constants.TILE_SIZE, Constants.TILE_SIZE);
My formulas are wrong someway...
The Slot object holds its x (i, row) in the matrix, and y (j, column) in the matrix.
The Actor object holds the slot, and calculates its position in the screen with the formulas above.
Another question: what are float x and float y in the dragStart method?
UPDATE
The correct formula for y is:
y = Constants.APP_HEIGHT - Constants.VERTICAL_OFFSET - (Constants.TILE_SIZE * slot.getX());
But the dragStart still does not work. It is totally out of phase.
The dragging does not start when i click on the actor, but if i click on an area in the top-right corner of the screen.
UPDATE 2
The problem is the positioning of the Table. It is totally messed up.
UPDATE 3
With table.setDebug(true) i verified that the table is at the correct position. So... i really don't know what is happening.
For drag and drop i implemented as follows:
myActor.addListener(new DragListener(){
public void touchDragged(InputEvent event, float x, float y, int pointer){
myActor.moveBy(x-firstItem.getWidth()/2,y-firstItem.getHeight()/2);}});

I have 2 Achartengine XYSeries problems

I’m having 2 problems with a simple XYSeries line graph.
When the absolute value of the difference between the last plotted point and the next plotted point is less than 11 the label on the next plotted point goes missing. I want all the labels to display.
I have some (not all) missing vertical grid lines and don’t see why. I want a vertical grid line for every XY coordinate.
Thanks for the help. Here's the code.
String glucoseLegendText = getString(R.string.glucose_legend_text);
XYSeries series = new XYSeries(glucoseLegendText);
datasource = new HistoryDataSource(this);
datasource.open();
Cursor c = datasource.getQuery();
c.moveToFirst();
int cnt = c.getCount();
int minValue = 0;
int maxValue = 0;
for (int i = 0; i < cnt; i++) {
int glucoseValue = c.getInt(2);
series.add(i, glucoseValue);
if (i == 0 || glucoseValue < minValue)
minValue = glucoseValue;
if (glucoseValue > maxValue)
maxValue = glucoseValue;
c.moveToNext();
}
datasource.close();
XYMultipleSeriesDataset dataset = new XYMultipleSeriesDataset();
dataset.addSeries(series);
XYSeriesRenderer renderer = new XYSeriesRenderer();
renderer.setColor(Color.BLUE);
renderer.setPointStyle(PointStyle.CIRCLE);
renderer.setFillPoints(true);
renderer.setLineWidth(3);
renderer.setDisplayChartValues(true);
renderer.setChartValuesTextSize(15);
renderer.setChartValuesTextAlign(Align.LEFT);
XYMultipleSeriesRenderer mRenderer = new XYMultipleSeriesRenderer();
mRenderer.addSeriesRenderer(renderer);
mRenderer.setShowGrid(true);
mRenderer.setGridColor(Color.BLACK);
mRenderer.setXLabels(cnt); // to control number of grid lines
mRenderer.setYLabels(cnt); // to control number of grid lines
mRenderer.setXLabelsColor(Color.YELLOW);
mRenderer.setPointSize(5);
mRenderer.setYLabelsAlign(Align.RIGHT);
mRenderer.setLegendTextSize(15);
mRenderer.setZoomButtonsVisible(true);
mRenderer.setYAxisMin(minValue - 2); // buffer bottom
mRenderer.setYAxisMax(maxValue + 3); // buffer top
// Populate the X labels with the dates and times
c.moveToFirst();
for (int d = 0; d < cnt; d++) {
timeStamp = c.getString(1);
date = timeStamp.substring(0, 5);
time = timeStamp.substring(9, 14);
if (date.equals(dateLast)) {
mRenderer.addXTextLabel(d, "\n" + time);
} else
mRenderer.addXTextLabel(d, "\n" + time + "\n" + date);
dateLast = date;
c.moveToNext();
}
c.close();
GraphicalView gview = ChartFactory.getTimeChartView(this, dataset,
mRenderer, "");
LinearLayout layout = (LinearLayout) findViewById(R.id.Chart);
layout.addView(gview);
For the first question, you can control the labels display using
renderer.setXLabels(approximateNumberOfLabels);
For the second question, the grid lines are displayed along the labels.