Archivio

Archivio per febbraio 2009

C#: Convertire string array in int array

27 febbraio 2009 zaragon 3 commenti

A futura memoria:

string[] stringArray = { "1", "2", "3"};
int[] intArray = Array.ConvertAll<string, int>(stringArray, delegate(string s) { return int.Parse(s); });

Categorie:C# Tag:

EXT JS: Modificare le dimensioni dei font con Ext.Slider

15 febbraio 2009 zaragon Nessun commento

Da parecchio tempo sono impegnato nella realizzazione di un importante progetto con l’ ausilio del framework javascript Extjs. Tra le tante funzionalità richieste dal cliente, c’è quella di modificare le dimensioni del font dei testi e lo Slider mi è venuto in aiuto. Vi posto un pò di codice che ho scritto per l’ occasione sperando che possa esservi utile come spunto. Se avete qualche suggerimento sono tutto orecchi…

Dichiaro lo slider e l’ evento

var slider = new Ext.Slider({ width: 100
                            , value: 12
                            , increment: 1
                            , minValue: 9
                            , maxValue: 15
                            , animate: false
                            , plugins: new Ext.ux.SliderTip()
});
slider.on('changecomplete', this.onChangecomplete, this);
this.sliderValue = 12;

changeFontSize: function(startValue, endValue) {
    this.removeClass(String.format('doc-font-{0}', this.sliderValue));
    this.addClass(String.format('doc-font-{0}', endValue));

},

onChangecomplete: function(slider, newValue) {
    this.changeFontSize(this.sliderValue, newValue);
    this.sliderValue = newValue;
}

Nella dichiarazione ho utilizzato il seguente plugin:

/**
* @class Ext.ux.SliderTip
* @extends Ext.Tip
* Simple plugin for using an Ext.Tip with a slider to show the slider value
*/
Ext.ux.SliderTip = Ext.extend(Ext.Tip, {
    minWidth: 10,
    offsets: [0, -10],
    init: function(slider) {
        slider.on('dragstart', this.onSlide, this);
        slider.on('drag', this.onSlide, this);
        slider.on('dragend', this.hide, this);
        slider.on('destroy', this.destroy, this);
    },

    onSlide: function(slider) {
        this.show();
        this.body.update(this.getText(slider));
        this.doAutoWidth();
        this.el.alignTo(slider.thumb, 'b-t?', this.offsets);
    },

    getText: function(slider) {
        return slider.getValue();
    }
});

Categorie:Ajax Tag: